import urllib.requestdef callback(blocknum, blocksize, totalsize): ???‘‘‘ ???:param blocknum: 已下载数据块 ???:param blocksize: 数据块大小 ???:param totalsize: 远程文件大小 ???:return: ???‘‘‘ ???percent = 100.0*blocknum*blocksize/totalsize ???if(percent>100): ???????percent = 100 ???print(‘%.2f%%‘ % percent)url = ‘http://www.sina.com.cn‘local = ‘f:\\sina.html‘a,b = urllib.request.urlretrieve(url, local, callback) #从远程下载数据print(a)print(b)
#输出结果0.00%1.39%
...
88.90%94.46%95.84%97.23%98.62%100.00%f:\sina.htmlServer: nginxDate: Fri, 08 Jun 2018 02:50:40 GMTContent-Type: text/htmlContent-Length: 589755Connection: closeLast-Modified: Fri, 08 Jun 2018 02:50:01 GMTVary: Accept-EncodingX-Powered-By: shci_v1.03Expires: Fri, 08 Jun 2018 02:51:22 GMTCache-Control: max-age=60Age: 18Via: http/1.1 cnc.guangzhou.ha2ts4.59 (ApacheTrafficServer/6.2.1 [cHs f ])X-Cache: HIT.59X-Via-CDN: f=edge,s=cnc.guangzhou.ha2ts4.60.nb.sinaedge.com,c=42.49.109.219;f=Edge,s=cnc.guangzhou.ha2ts4.59,c=112.90.6.60X-Via-Edge: 1528426240834db6d312aee065a707941b2ee
urllib.request.urlretrieve用法
原文地址:https://www.cnblogs.com/logo-88/p/9154476.html