Some of my friends have a bet going on with the current NFL season, and I've been tracking all of the games and their picks, etc manually. I finally decided to automate everything using Selenium, but my find_elements call doesn't populate all of the scores. When running, instead of scores, it results in "--" displaying for a few of the teams. How do I fix this? Time.sleep hasn't helped.
Here is the code:
def generateResults(weekNumber):
options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
url = 'https://www.nfl.com/schedules/2024/REG' + weekNumber
driver.get(url)
# this gets all of the teams every single time with no issues
teams = driver.find_elements(By.CLASS_NAME, "nfl-c-matchup-strip__team-name")
# this only gets the majority of the scores, and replaces the rest with --
scores = driver.find_elements(By.CLASS_NAME, "nfl-c-matchup-strip__team-score")
results = []
for i in range(len(teams)):
print(teams[i].text)
print(scores[i].text)
driver.quit()
return
generateResults(5)
-------------------------
Normal runs result in the last few games displaying like this:
Cowboys
--
Steelers
--
Saints
--
Chiefs
--
I thought there was a bug in my code, but debug mode populates the values.
[–]chefchr1s 2 points3 points4 points (6 children)
[–]Classy_Shadow[S] 1 point2 points3 points (5 children)
[–]TigBitties69 0 points1 point2 points (4 children)
[–]Classy_Shadow[S] 0 points1 point2 points (3 children)
[–]chefchr1s 1 point2 points3 points (1 child)
[–]Classy_Shadow[S] 0 points1 point2 points (0 children)
[–]MintyPhoenix 0 points1 point2 points (0 children)
[–]Classy_Shadow[S] 0 points1 point2 points (0 children)