Python下载并解压zip文件

import zipfile
import requests

url = "http://www.51dev.com/ids.zip"
path = "ids.zip"
r = requests.get(url)
try:
    with open(path, "wb") as code:
        code.write(r.content)

    zip_file = zipfile.ZipFile(path)
    zip_list = zip_file.namelist() # 得到压缩包里所有文件

    for f in zip_list:
        zip_file.extract(f, "ids") # 循环解压文件到指定目录

    zip_file.close()
    print("ok")
except FileNotFoundError:
    print(e)

 

你可能感兴趣的