[英]Unable to download files using Python Requests
可以从 HLTV 手动下载文件(输入 url 并输入,文件被下载)但不能与 Python 请求一起使用,并返回一个未知的 9KB 文件。
工具集:请求 2.25.1、Python 3.9 64 位、PyCharm 2021.1.1 专业版、ZAEA23489CE3AA9B6406EBB28E0CDA403。
下面是一个最小的工作示例:
import requests
r = requests.get('https://www.hltv.org/download/demo/64081')
with open('C:\\new\\test.rar', 'wb') as f:
f.write(r.content)
尝试指定User-Agent
HTTP header:
import requests
url = "https://www.hltv.org/download/demo/64081"
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0"
}
with open("test.rar", "wb") as f:
f.write(requests.get(url, headers=headers).content)
编写 test.rar(从ls -alF test.rar
test.rar
):
-rw-r--r-- 1 root root 279701450 May 3 22:27 test.rar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.