import urllib2
req = urllib2.Request('http://www.python.org/')
#
# Here we request that bytes 18000 19000 be downloaded.
# The range is inclusive, and starts at 0.
#
req.headers['Range'] = 'bytes=%s-%s' % (18000, 19000)
f = urllib2.urlopen(req)
# This shows you the *actual* bytes that have been downloaded.
range=f.headers.get('Content-Range')
print(range)
# bytes 18000-18030/18031
print(repr(f.read()))
# ' </div>\n</body>\n</html>\n\n\n\n\n\n\n'
您可以通过发送带有
Range
头的GET请求部分下载:请注意检查
Content-Range
以了解实际下载了哪些字节,因为您的范围可能超出了范围,并且/或不是所有服务器似乎都尊重Range
头。在相关问题 更多 >
编程相关推荐