record-11 网络编程 下载

from time import time,sleep

now1=time()

#import urllib.request
#urllib.request.urlretrieve()

#from urllib import request
#request.urlretrieve()

def abc1(a,b,c):
    print(a) #a接收的是下载过程中数据包的序号
    print(b) #b接收的是下载过程中每个数据包的大小
    print(c) #c接收的是下载的总资源大小

def abc2(a,b,c):
    global now1
    now2=time()
    result=(a+1)*b/c
    if now2-now1>5:
        print('当前下载进度%.2f%%'%result)
        now1=now2

from urllib.request import urlretrieve
#urlretrieve() #下载网络资源
#第一个参数是URL 协议声明+IP/域名+端口+资源路径
#第二个参数是本地保存路径
#第三个参数是函数,要求这个函数必须有三个形参

url='https://www.python.org/ftp/python/3.6.4/python364.chm'
path='D:\\python364.chm'

urlretrieve(url,path,abc2)

  

posted @ 2018-01-18 21:31  minkillmax  阅读(125)  评论(0编辑  收藏  举报