【发布时间】:2019-04-05 16:42:33
【问题描述】:
我正在尝试下载一个二进制文件并将其以其原始名称保存在磁盘上 (linux)。
有什么想法吗?
import requests
params = {'apikey': 'xxxxxxxxxxxxxxxxxxx', 'hash':'xxxxxxxxxxxxxxxxxxxxxxxxx'}
response = requests.get('https://www.test.com/api/file/download', params=params)
downloaded_file = response.content
if response.status_code == 200:
with open('/tmp/', 'wb') as f:
f.write(response.content)
【问题讨论】:
-
我更喜欢处理请求
-
这是请求。看看链接。你要做的就是将
requests.get的stream参数设置为True,然后分块读取流并写入二进制文件(open("file", "wb") -
我知道如何下载文件,只需要知道如何将其保存为原始名称
-
你说的原名是什么意思?
标签: python