urlretrieve方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #!/usr/bin/python #encoding:utf-8 import urllib import os def Schedule(a,b,c):
'''''
a:已经下载的数据块
b:数据块的大小
c:远程文件的大小
'''
per = 100.0 * a * b / c
if per > 100 :
per = 100
print '%.2f%%' % per url = 'http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2' local = os.path.join( '/data/software' , 'Python-2.7.5.tar.bz2' )
****** 99.33% 99.40% 99.47% 99.54% 99.60% 99.67% 99.74% 99.81% 99.87% 99.94% 100.00% 说明: 查看urllibe模块提供的urlretrieve函数。 help (urllib.urlretrieve) urlretrieve(url, filename = None , reporthook = None , data = None ) 参数finename指定了保存本地路径(如果参数未指定,urllib会生成一个临时文件保存数据。) |
转载于:https://blog.51cto.com/lubing/1239293