Skip to main content
 首页 » 编程设计

python selenium xpath解决方案

2024年10月17日7mq0036

可以这样做:

  • 在文档中我有几个表:

    ...

    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 类 = 奖金

    ....

  • 类 kx包含:

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

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

是否有可能根据后代的属性值(在我的例子中为 odd)获取祖先的内容(在我的例子中为类 eu=1.90)

请您参考如下方法:

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

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