How to download a zip file from a site (python)

27,534

Solution 1

You can use urllib.urlretrieve this way:

urlretrieve(your_url, your_zip_path)

Solution 2

You have to consider something like:

import urllib2
response = urllib2.urlopen('http://www.website.com/log.zip')
zipcontent= response.read()

and now you write the file to disk :)

with open("log.zip", 'w') as f:
    f.write(zipcontent)

You can also check: Python and urllib

download a zip file to a local drive and extract all files to a destination folder using python 2.5

Share:
27,534
Ofek .T.
Author by

Ofek .T.

Hi there

Updated on May 27, 2020

Comments

  • Ofek .T.
    Ofek .T. about 4 years

    There is a site with logs and each log is in zip (for space saving). How can I download it from the site?

    ( urllib / urllib2 )(?)

  • instinct
    instinct about 5 years
    As said in doc, Deprecated since version 2.6: The urlopen() function has been removed in Python 3 in favor of urllib2.urlopen(). this answer needs some updates from Python3's perspective.