I want to download the files of all teams for season 2015-2016 to 2018-2019. However, I am trying to loop through Xpaths that are identical except one number in a bracket to select the different teams and years; the last bracket where I replaced the number with %b and %i. Here is my code:
from selenium import webdriver
import csv
from selenium.webdriver.support.ui import Select
from datetime import date, timedelta
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import TimeoutException
chromedriver =("C:/Users/Michel/Desktop/python/package/chromedriver_win32/chromedriver.exe")
driver = webdriver.Chrome(chromedriver)
driver.get("https://evolving-hockey.com/")
#Click Games and then game logs
Gamestab= driver.find_element_by_xpath("/html/body/nav/div/ul/li[6]/a")
Gamestab.click()
Gameslog= driver.find_element_by_xpath("/html/body/nav/div/ul/li[6]/ul/li[3]/a")
Gameslog.click()
# Click Teams tab
Teamstab= driver.find_element_by_xpath("//*[@id='tab-3278-3']/div/ul/li[3]/a")
Teamstab.click()
# Loop all teams and all seasons
## TEAM
for b in range(1,33):
Team= driver.find_element_by_xpath("//*[@id='tab-3959-3']/div/div[1]/div[1]/div/div/div")
Team.click()
Teamname= driver.find_element_by_xpath("//*[@id='tab-3959-3']/div/div[1]/div[1]/div/div/div/div[2]/div/div[%b]" %(b))
Teamname.click()
# ## Season- 20152016to20182019
for i in range(1,5):
Season=driver.find_element_by_xpath("//*[@id='tab-3959-3']/div/div[1]/div[2]/div/div/button")
Season.click()
Season1819=driver.find_element_by_xpath("//*[@id='tab-3959-3']/div/div[1]/div[2]/div/div/div/ul/li[%s]" %(i))
Season1819.click()
I think it should work by using % and assigning a variable that is, in fact, the iterative element in the for loop, just like I tried, but it does not work.