HaAbs
HaAbs

Reputation: 47

Another way to get to the element instead of xpath

enter image description here

I want to extract data ["Over/Under +0.5", "1.04", "11.46", "95.3%"] by using python(selenium) for more than 10 pages but I have a problem with getting the exact value with Xpath inside the table the number inside div[] change in each web page is there any way to get to the same value inside the table? for example : page1

'//*[@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

Upvotes: 0

Views: 85

Answers (1)

E.Wiest
E.Wiest

Reputation: 5905

The following XPath should work :

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

Output : 3 nodes > Over/Under/Payout

If you want to keep the "Over/Under +0.5" element :

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

or

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

Output : 4 nodes

Upvotes: 1

Related Questions