文章内容
2021/4/8 16:32:01,作 者: 黄兵
Python requests下载文件
最近需要通过Python自动下载文件,使用的是requests包,以下是示例代码:
def download_maxmind_file():
import io
import requests
import zipfile
# 远程下载maxmind_asn_csv file
r = requests.get(DOWNLOAD_MAXMIND_CSV_URI)
z = zipfile.ZipFile(io.BytesIO(r.content))
maxmind_save_dir = os.path.join(os.getcwd(), 'files/maxmind')
z.extractall(maxmind_save_dir)
参考资料:
1、Download Returned Zip file from URL
评论列表