如何从站点下载 zip 文件 (python)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16760992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:35:21  来源:igfitidea点击:

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

pythonfiledownloadzip

提问by Ofek .T.

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

有一个带有日志的站点,每个日志都是 zip 格式的(为了节省空间)。我如何从网站上下载它?

( urllib / urllib2 )(?)

( urllib / urllib2 )(?)

采纳答案by aldeb

You can use urllib.urlretrievethis way:

你可以这样使用urllib.urlretrieve

urlretrieve(your_url, your_zip_path)

回答by asdf

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

您还可以检查: Python 和 urllib

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

将 zip 文件下载到本地驱动器并使用 python 2.5 将所有文件解压缩到目标文件夹