- >>> import urllib2
- >>> req = urllib2.Request('http://www.python.org/')
- #下载19000到20000字节的片段
- >>> req.headers['Range'] = 'bytes=%s-%s' % (19000, 20000)
- >>> f = urllib2.urlopen(req)
- >>> pagerange = f.headers.get('Content-Range')
- >>> print pagerange
- bytes 19000-19189/19190
- >>> print repr(f.read())
- '</div>\n\tCopyright © 1990-2012, <a href=\'/psf/\'>Python Software Foundation</a><br/>\n\t<a href="/about/legal">Legal Statements</a>\n </div>\n\n\n </div>\n </div>\n</body>\n</html>\n\n\n\n\n\n\n'
- >>>
来源: http://www.phpxs.com/code/1004948/