码迷,mamicode.com
首页 > Web开发 > 详细

urllib.request.urlretrieve用法

时间:2018-06-08 12:16:43      阅读:810      评论:0      收藏:0      [点我收藏+]

标签:mod   call   return   输出   modified   odi   cse   block   nbsp   

import urllib.request
def 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.html Server: nginx Date: Fri, 08 Jun 2018 02:50:40 GMT Content-Type: text/html Content-Length: 589755 Connection: close Last-Modified: Fri, 08 Jun 2018 02:50:01 GMT Vary: Accept-Encoding X-Powered-By: shci_v1.03 Expires: Fri, 08 Jun 2018 02:51:22 GMT Cache-Control: max-age=60 Age: 18 Via: http/1.1 cnc.guangzhou.ha2ts4.59 (ApacheTrafficServer/6.2.1 [cHs f ]) X-Cache: HIT.59 X-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.60 X-Via-Edge: 1528426240834db6d312aee065a707941b2ee

 

urllib.request.urlretrieve用法

标签:mod   call   return   输出   modified   odi   cse   block   nbsp   

原文地址:https://www.cnblogs.com/logo-88/p/9154476.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!