This is a follow up question to my previous problem
driver = webdriver.Chrome(executable_path="C:/Users/Joonas/PycharmProjects/Dictionaries/chromedriver.exe")
driver.get("http://naturalstattrick.com/games.php")
driver.minimize_window()
away_team = driver.find_element_by_xpath("//*[@id='teams_wrapper']/div[2]/div[3]/div[2]/div/table/tbody/tr[1]/td[2]") #Arizona
home_team = driver.find_element_by_xpath("//*[@id='teams_wrapper']/div[2]/div[3]/div[2]/div/table/tbody/tr[2]/td[2]") #Vegas
print(away_team.text, home_team.text)
Output:
Arizona Coyotes Vegas Golden Knights
I want to loop the string mentioned above, so that after each loop (Game) /tr[ ] changes. The strings of next game's teams are as follows:
"//*[@id='teams_wrapper']/div[2]/div[3]/div[2]/div/table/tbody/tr[3]/td[2]" #Chicago
"//*[@id='teams_wrapper']/div[2]/div[3]/div[2]/div/table/tbody/tr[4]/td[2]" #Washington
I am trying to build a program that scrapes all the games and prints each game separately on their respective rows as I run the program:
Game1 away team Game1 home team
Game2 away team Game2 home team
Game3 away team Game3 home team
Expected Output:
Arizona Coyotes Vegas Golden Knights
Chicago Blackhawks Washington Capitals
etc....