小尹学python

导航

Python:下载压缩文件并解压到相应文件夹案例

import requests
import shutil
# 1.下载文件
file_url = 'https://files.cnblogs.com/files/wupeiqi/HtmlStore.zip'
res = requests.get(url=file_url)
with open(r'D:\Python\路飞\练习\Store.zip',mode='wb') as f:  # 需要用wb模式
    f.write(res.content)
shutil.unpack_archive(filename=r'D:\Python\路飞\练习\Store.zip',extract_dir=r'D:\Python\路飞\练习\files\html',format='zip')

posted on 2021-10-10 20:00  小尹学python  阅读(442)  评论(0编辑  收藏  举报