有一个包含日志的站点,每个日志都是zip(节省空间)。 如何从网站下载?
(urllib / urllib2)(?)
答案 0 :(得分:10)
您可以这样使用urllib.urlretrieve
:
urlretrieve(your_url, your_zip_path)
答案 1 :(得分:2)
您必须考虑以下内容:
import urllib2
response = urllib2.urlopen('http://www.website.com/log.zip')
zipcontent= response.read()
现在您将文件写入磁盘:)
with open("log.zip", 'w') as f:
f.write(zipcontent)
您还可以查看: Python and urllib
download a zip file to a local drive and extract all files to a destination folder using python 2.5