-1

I have a direct download link address to a compressed zip file that contains an installer of program that I would like to install.

That being said I will only ask one question at a time...

How would I download and save it to disk ready for the next step of unzipping it in code?

Is there a specific module that deals with this?

Can it be done silently in the background without opening up a browser?

Any help would be very much appreciated

Thanks in advance

0

1 Answer 1

1

The most direct way uses good old urllib -- specifically https://docs.python.org/2/library/urllib.html#urllib.urlretrieve :

fn, _ = urllib.urlretrieve('http://what.ever.com/thefile.zip')

will set variable fn to the filename to which that file has been retrieved and locally saved.

If you want to decide exactly where to put the file, pass the filename yourself as the second argument of urlretrieve.

5
  • @ Alex Martelli Thank you this looks like what I need, but, just to be clear, Is the second argument the path? Is the filename stored in fn still going to be kept the same as the one retrieved and then appended to the path? I am quite new to programming so the simplest breakdown would help me a lot... Commented Jan 17, 2015 at 22:10
  • @ChrisStone, yes, but it's optional -- urlretrieve will determine a temporary path (and return it as the first of two items) if you don't tell it where to put the retrieved resource. Commented Jan 17, 2015 at 22:13
  • @ChrisStone, no, the docs I posted the URL for are for Python 2, and urllib is an ancient part of the standard library. Pls edit your Q to post exactly what code you're using and the full traceback of any error you get (with four extra spaces at the start of each line so SO will format it readably) -- impossible to help you otherwise (comments don't let you have readable code or error tracebacks). Commented Jan 17, 2015 at 23:21
  • I'm sorry it was my mistake there was no error, just a silly mistake that has now been rectified... I can delete my edit and you can delete your comment if you like Commented Jan 18, 2015 at 0:05
  • @ChrisStone OK, so I hope you can accept this answer (click on the checkmark outline to the left of the answer) as being helpful. Commented Jan 18, 2015 at 0:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.