【问题标题】:xpath preceding-sibling solutionxpath 前同级解决方案
【发布时间】:2016-12-13 14:40:45
【问题描述】:

现在我需要从 <td> 161.5 </td> 获取类奇数或文本的内容

所以我写了:

element = driver.find_elements_by_xpath('//td[span[@class=" odds-wrap " and @eu="1.90"]]/preceding-sibling::td')

而且它有效。

我的问题是:是否可以使用更多条件获得相同的内容,例如title="bet365".. 所以,我想获得相同的结果,但使用来自另一个同级元素的更多条件..

编辑

element = driver.find_elements_by_xpath('//tr[preceding-sibling::td/span[@class=" odds-wrap " and @eu="1.90"] and following-sibling::td/div/a[@title="bet365"]]')
for ele in element:
    print(ele.text)

没有找到和打印任何东西,我不知道为什么

【问题讨论】:

  • 如果你想去另一个方向,还有following-sibling。或者你想要“介于”之类的东西?

标签: python selenium xpath


【解决方案1】:

你可以结合preceding-siblingfollowing-sibling

//td[following-sibling::td/span[@class=" odds-wrap " and @eu="1.90"] and preceding-sibling::td/a[@title="bet365"]]

【讨论】:

  • 谢谢,我正在尝试这种组合,但目前没有结果
  • @JakeSully365 理论上应该可以工作,您能否分享一个指向目标页面的链接,以便我也可以尝试重现此问题?谢谢。
【解决方案2】:

使用以下xpath

//span[@class=" odds-wrap " and @eu="1.90"]/preceding::a[@title='bet365']/following::td[1]

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-12-19
  • 2018-04-28
  • 1970-01-01
  • 1970-01-01
  • 2016-12-03
  • 2014-04-17
  • 2022-07-29
  • 2023-02-20
相关资源
最近更新 更多