【问题标题】:python selenium xpath solutionpython selenium xpath 解决方案
【发布时间】:2016-12-12 23:17:30
【问题描述】:

可以这样做:

  • 在文档中我有几个表格:

    ...

    table id="odds_ou_159.5"

    table id="odds_ou_160.5"

    table id="odds_ou_161.5"

    ...

  • 表包含几个类:

    ...

    tr class = odd>

    tr class = odd>

    ...

  • odd 类包含:

    td class = bookmaker ...

    td> 161.5 </td>

    td class = kx

    td class = kx

    td class= 奖金

    ....

  • kx 类包含:

    span class=" odds-wrap " eu="1.90"> 1.90

现在我需要从 <td> 161.5 </td> 获取类奇数或文本的内容,但我的条件必须是 eu="1.90"

是否可以根据后代的属性值(在我的情况下为 eu=1.90)获取祖先的内容(在我的情况下为 odd

【问题讨论】:

    标签: python selenium xpath


    【解决方案1】:

    试试这个XPath,如果有任何问题,请告诉我:

    //td[span[@eu="1.90"]]/preceding-sibling::td
    

    【讨论】:

    • @JakeSully,在代码中使用 1.90 时使用单引号,因为我们使用双引号在 findElement* 方法中提供 XPath。
    • 谢谢你,我写了'//td[span[@class="odds-wrap" and @eu="1.90"]]/preceding-sibling::td' 并且它有效跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多