0

The elements in the web-page I'm scraping are found by one of two x_paths even though the elements are almost the same. Basically, some of the elements have an icon next to them and some of them don't. But I'm not interested in the icon, I'm just scraping the numbers next to it.

For data with an icon I use:

driver.find_elements_by_xpath('//a[@class="in-match"]')

For data without an icon, I use:

driver.find_elements_by_xpath('//td[@class="table-main__detail-odds table-main__detail-odds--first"]')

I need my scraper to be able to look for either of these two things. It is important that it looks for them simultaneously so that the order scraped is the same as the order that the data appears on the page.

This seems like a simple question, but I'm really not sure how to do it.

Thanks.

Ratmir Asanov
  • 5,433
  • 5
  • 20
  • 36
Michael
  • 265
  • 1
  • 5
  • Possible duplicate of [XPath OR operator for different nodes](https://stackoverflow.com/questions/5350666/xpath-or-operator-for-different-nodes) – JeffC Feb 28 '19 at 20:23

1 Answers1

0

You can use or condition in your XPath to match both condtions like shown below:

locator = '//a[@class="in-match" or @class="table-main__detail-odds table- main__detail-odds--first"]'
driver.find_elements_by_xpath(locator)

This will match elements with both class.

Ratmir Asanov
  • 5,433
  • 5
  • 20
  • 36
Thanthu
  • 2,648
  • 19
  • 36