根据this https://stackoverflow.com/questions/23602412/only-download-a-part-of-the-document-using-python-requests我可以使用 Range 标头仅下载 html 页面的一部分,但使用以下代码:
import requests
url = "http://stackoverflow.com"
headers = {"Range": "bytes=0-100"} # first 100 bytes
r = requests.get(url, headers=headers)
print r.text
我得到了整个 html 页面。为什么它不起作用?
如果网络服务器不支持Range
标头,它将被忽略。
尝试使用其他支持标头的服务器,例如tools.ietf.org
:
import requests
url = "http://tools.ietf.org/rfc/rfc2822.txt"
headers = {"Range": "bytes=0-100"}
r = requests.get(url, headers=headers)
assert len(r.text) <= 101 # not exactly 101, because r.text does not include header
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)