另一种获取元素而不是xpath的方法

问题描述 投票:0回答:1

enter image description here

我想使用python(selenium)提取数据[“ Over / Under +0.5”,“ 1.04”,“ 11.46”,“ 95.3%”]超过10页,但获取准确值存在问题在表格内使用Xpath,每个网页中div []内的数字都会更改有什么办法可以在表内获得相同的值?例如 :第1页

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

page2

'// * [@ 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个回答
0
投票

以下XPath应该起作用:

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

输出:3个节点>大/小/付款

如果要保留“大于/小于+0.5”元素:

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

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

输出:4个节点

© www.soinside.com 2019 - 2024. All rights reserved.