I am scraping a website that has a list of football games generated using JavaScript. I have written the following line that creates a list of all the game elements on the page:
list = browser.find_elements_by_xpath('//*[@data-sportid="1"]')
If I then write
for game in list:
print game.text
it prints all the text fields contained in each of the games (home team name, away team name, etc.)
However, the loop
for game in list:
print game.find_element_by_xpath('//*[@class="home-team"]').text
prints the very first home team's name in the page for each iteration of the loop.
It appears that game.find_element_by_xpath
is searching the entire page, and not just this game
element, and so it keeps returning the first home team name on the page.
How can I search for a child element within each item of the list?
EDIT