python3 显示下载进度

来源:互联网 发布:现货交易平台软件 编辑:程序博客网 时间:2024/05/16 08:13
import urllibdef download(imagelist,local):    x=1    for i in imagelist:        socket.setdefaulttimeout(1000)        urllib.request.urlretrieve(i,local+'%s.jpg'%x,schedule)        x+=1        print("*********")def schedule(a,b,c):    '''''    a:已经下载的数据块    b:数据块的大小    c:远程文件的大小    '''    per = 100.0 * a * b / c    if per > 100 :        per = 100    print('%.2f%%' % per)

urllib.request.urlretrieve()第三个参数为回调函数

0 0