Selenium find_elements not populating all elements /u/Classy_Shadow Python Education

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. 

submitted by /u/Classy_Shadow
[link] [comments]

​r/learnpython 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. submitted by /u/Classy_Shadow [link] [comments] 

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. 

submitted by /u/Classy_Shadow
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *