python requests 下载二进制文件 作者:马育民 • 2025-01-28 15:28 • 阅读:10010 # 介绍 定义 `download_blob()` 函数,如果能够正常访问,就将二进制文件保存到指定位置,否则就打印服务器返回的内容 ``` def download_blob(url,save_path): ''' 下载 二进制 文件 ''' location = parse_url(url) filename = location.pathname # 文件名 with requests.get(url,headers=headers) as resp: if resp.status_code == 200: print() print("请求成功,url:",url) with open(save_path + filename,'wb' ) as f: f.write(resp.content) else: print() print("请求错误,url:",url) print(resp.text) print() ``` 原文出处:http://malaoshi.top/show_1GWULhyxZFQ.html