程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python segmented download file

編輯:Python

Segmented downloading when downloading large files will speed up the download process , Almost all downloadable software has similar features . stay python How to realize segmented file downloading in ?

>>> import urllib2
>>> req = urllib2.Request('http://www.python.org/')
download 19000 To 20000 Fragments of bytes
>>> 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 &copy; 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'
>>> </pre> 

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved