6

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 )(?)

Ofek .T.
  • 741
  • 3
  • 10
  • 29

2 Answers2

10

You can use urllib.urlretrieve this way:

urlretrieve(your_url, your_zip_path)
aldeb
  • 6,588
  • 5
  • 25
  • 48
  • 2
    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. – instinct Apr 01 '19 at 12:33
4

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

Community
  • 1
  • 1
asdf
  • 685
  • 7
  • 23