【问题标题】:Another way to get to the element instead of xpath获取元素而不是 xpath 的另一种方法
【发布时间】:2020-06-04 22:18:05
【问题描述】:

我想通过使用 python(selenium) 提取超过 10 页的数据 ["Over/Under +0.5"、"1.04"、"11.46"、"95.3%"],但我无法获得准确的数据表格内带有 Xpath 的值 div[] 内的数字在每个网页中发生变化 有什么办法可以在表中获得相同的值? 例如 : 第1页

'//*[@id="odds-data-table"]/div[12]/div/strong'

第2页

'//*[@id="odds-data-table"]/div[11]/div/strong'

https://www.oddsportal.com/soccer/england/premier-league-2017-2018/newcastle-utd-arsenal-vLKS6e2j/?r=1#over-under;2

【问题讨论】:

标签: python selenium xpath


【解决方案1】:

以下 XPath 应该可以工作:

//div[@class="table-header-light odd first"]//*[contains(text(),".")][not(parent::strong)]

输出:3 个节点 > Over/Under/Payout

如果您想保留“Over/Under +0.5”元素:

//div[@class="table-header-light odd first"]//*[contains(text(),".")]

(//div[@class="table-header-light odd first"]//text())[position()<=4]

输出:4 个节点

【讨论】:

    猜你喜欢
    • 2011-10-23
    • 2011-07-10
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-24
    • 1970-01-01
    相关资源
    最近更新 更多