[英]python3, how to download zip files
I have a simple script that download zip files to the folder, i don't know what i am doing wrong, the files are always corrupted,I attached a reproducible example, first I get the list of files, which works fine, but when I download those files, it complains that the zip is corrupted.我有一个将 zip 文件下载到文件夹的简单脚本,我不知道我做错了什么,文件总是损坏,我附上了一个可重现的例子,首先我得到了文件列表,它工作正常,但是当我下载了这些文件,它抱怨 zip 已损坏。
import re ,shutil
from urllib.request import urlopen
url = "http://nemweb.com.au/Reports/Current/Dispatch_SCADA/"
result = urlopen(url).read().decode('utf-8')
pattern = re.compile(r'[\w.]*.zip')
filelist = pattern.findall(result)
for x in filelist:
with urlopen(url) as source, open(x, 'w+b') as target:
shutil.copyfileobj(source, target)
You always use the same url
to HTML page您总是对 HTML 页面使用相同的
url
You have to download url + "/" + x
你必须下载
url + "/" + x
for x in filelist:
with urlopen(url + "/" + x) as source, open(x, 'w+b') as target:
shutil.copyfileobj(source, target)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.