zip 下载解压

Posted duanhaoxin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zip 下载解压相关的知识,希望对你有一定的参考价值。

import requests
import os
import zipfile

url="https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-modified.json.zip"

headers={
"Host":"nvd.nist.gov",
"Cookie":"CMSPreferredCulture=en-US; CMSCsrfCookie=BnM2YPWY/10f0fLVdGlIR9I3RVn/4Jks9oHctMmX; ASP.NET_SessionId=nbby4gh330ocgwzp354yegm0; __utma=141729133.1560305428.1576834211.1576834211.1576834211.1; __utmc=141729133; __utmz=141729133.1576834211.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmb=141729133.4.8.1576834247314",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/73.0.3683.86 Safari/537.36"
}
html=requests.get(url=url,headers=headers)
with open("1.zip", "wb") as code:
for chunk in html.iter_content(chunk_size=1024): # 边下载边存硬盘
if chunk:
code.write(chunk)
root="./"
zip_file_path = os.path.join(root, ‘1.zip‘)
with zipfile.ZipFile(zip_file_path) as zf:
zf.extractall(root)

以上是关于zip 下载解压的主要内容,如果未能解决你的问题,请参考以下文章

ZIP格式的文件下载后怎么解压?

zip 下载解压

通过Django下载Zip文件,文件解压为cpzg

Jersey Client 下载 ZIP 文件并高效解压

解决:解压zip文件却变成cpgz文件

linux利用shell脚本下载文件并解压