'insert variable into url during for loop
I'm trying to do a scrape via a for loop. I just need to insert the date ranges in "seasons" each time through into the curly brackets in "url." I provided "base_url" as an example of the normal url if there is a better solution please let me know. However, "stats" in the url must be removed and the "," is necessary.
seasons = ['2021-2022','2020-2021','2019-2020','2018-2019','2017-2018']
#base_url = "https://fbref.com/en/comps/Big5/2020-2021/stats/players/2020-2021-Big-5-European-Leagues-Stats"
for season in seasons:
df_outfield = get_outfield_data(f'https://fbref.com/en/comps/Big5/{season}/',f'/players/{season}-Big-5-European-Leagues-Stats')
#Save csv file to Desktop
df_outfield.to_csv(export.csv',index=False)
df_outfield
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|