'How to scrape information?

I have encountered a problem where I am supposed to scrape the red cards and fouls conceded for several matches. However, some websites have a red card tuple and some don't.

Here is an example:

This is a website that has a red card stats, https://www.premierleague.com/match/66650, note that you have to press on the stats tab to see the info.

Here is another game without the red card info: https://www.premierleague.com/match/66690

I have gathered all the links in a for loop, and this is what I have done so far, but it does not work as the fouls clash with the red cards.

foulsHome = driver.find_element(By.XPATH, ''))
print(foulsHome.text)
foulsAway = driver.find_element(By.XPATH, '')
print(foulsAway.text)
try:
redHome = driver.find_element(By.XPATH, '')
print(redHome.text)
redAway = driver.find_element(By.XPATH, '')
print(redAway.text)
except:
pass

I do not know what to put in the XPATH part, I need help with solving this issue.

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source