Download file using partial download (HTTP)

前端 未结 3 2003
南方客
南方客 2020-11-27 03:14

Is there a way to download huge and still growing file over HTTP using the partial-download feature?

It seems that this code downloads file from scratch every time i

3条回答
  •  情书的邮戳
    2020-11-27 04:10

    It is possible to do partial download using the range header, the following will request a selected range of bytes:

    req = urllib2.Request('http://www.python.org/')
    req.headers['Range'] = 'bytes=%s-%s' % (start, end)
    f = urllib2.urlopen(req)
    

    For example:

    >>> req = urllib2.Request('http://www.python.org/')
    >>> req.headers['Range'] = 'bytes=%s-%s' % (100, 150)
    >>> f = urllib2.urlopen(req)
    >>> f.read()
    'l1-transitional.dtd">\n\n\n
                                                            
提交回复
热议问题