I am scraping data from a lottery website to store all the past results in a database.
I got a problem that almost all information I want to retrive is at /html/body/div[3]/h2 per page of each date the lottery y drawn, but only one of them is at /html/body/div[2]/h2
To fix it I used the following code.
try:
text = self.driver.find_element(By.XPATH, '/html/body/div\[3\]/h2').text
except :
text = self.driver.find_element(By.XPATH, '/html/body/div\[2\]/h2').text
It works but I don't like it. Is there a better way to handle this kind of discrepancies?