Download multiple xls files using Python

Chris Angelico rosuav at gmail.com
Thu Feb 12 19:19:20 EST 2015


On Fri, Feb 13, 2015 at 11:07 AM,  <polleysarah7 at gmail.com> wrote:
> Here is an example of my problem. I have for the moment a CSV file named "Stars" saved on my windows desktop containing around 50.000 different links that directly starts downloading a xls file when pressed. Each row contains one of these links. I would want with your help create some kind of script for this that will make some kind of loop thru each row and visit this different links so it can download these 50.000 different files.
>

Let's break that down into pieces.

1) You have a CSV file, from which you'd like to extract specific data (URLs).
2) You have a series of URLs, which you would like to download.

Python can do both of these jobs! The first is best handled by the csv
module, and the second by the requests module (which you'd have to get
off PyPI).

https://docs.python.org/3/library/csv.html
http://docs.python-requests.org/en/latest/

In short: Loop over the lines in the file, as returned by the CSV
reader, and for each line, fire off a request to fetch its XLS file,
and save it to disk. Given that you're working with 50K distinct URLs,
you'll want to have some kind of check to see if you already have the
file, so you can restart the downloader script.

Have fun!

ChrisA



More information about the Python-list mailing list