On the page above if you click ‘Download CSV’ it will download a CSV file to your computer. I would like to set up a nightly process to download that CSV. I’m happy to scrape the data as well, a CSV just seems easier. I’m not really finding anything. Help?
3
Answers
This will download the CSV for you and save it to
daily_stats.csv
in the folder that the script exists in. You’ll have to installrequests
too –python -m pip install requests
. How to do it nightly would be more a matter of what works best for you. I mean, you could just run it every night, or is your goal to have a process on your computer that would auto-run it?I suppose this will stop working in 2025, but you could just change the year in the URL at that point.
This defines a function (download_csv) that takes a URL and a filename as input. It uses the requests library to fetch the content of the webpage and saves it to the specified ‘filename’ on your computer.