-1

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
JF44
  • 41
  • 5
  • Does this answer your question? [Is there a Python equivalent to Ruby's string interpolation?](https://stackoverflow.com/questions/4450592/is-there-a-python-equivalent-to-rubys-string-interpolation) – Pranav Hosangadi May 12 '22 at 21:42
  • I tried a solution trying that but keep getting "IndexError: list index out of range." – JF44 May 12 '22 at 21:48
  • Then show what you tried and ask a question about that. [Mre], [ask], [question checklist](//meta.stackoverflow.com/q/260648/843953) – Pranav Hosangadi May 12 '22 at 21:50
  • `url` is a tuple of two strings. Is this intentional? – John Gordon May 12 '22 at 21:53
  • yes it is. here is how the docs show it in an example w/o a loop. `#Remove the 'stats', and pass the first and third part of the link as parameters like below df_team = get_team_data('https://fbref.com/en/comps/9/','/Premier-League-Stats','for')` – JF44 May 12 '22 at 21:56
  • A [mre] needs to be *reproducible*. Yours isn't because we don't know what `get_outfield_data` is. Your string interpolation is fine. This is a different problem that you need to add more details for us to answer. – Pranav Hosangadi May 12 '22 at 22:00

0 Answers0