读书人

Python上载文件显示进度

发布时间: 2012-09-04 14:19:30 作者: rapoo

Python下载文件,显示进度

import urlliburl = "http://www.top100.cn/download/dl.php?n=Eat+Dirt.mp3&al=sgchdnctugy"file = "e:/test.mp3"def reporthook(blocks_read,block_size,total_size):    if not blocks_read:        print ("Connection opened")    if total_size <0:        print "Read %d blocks"  % blocks_read    else:        print "downloading: %d KB, totalsize: %d KB" % (blocks_read*block_size/1024.0,total_size/1024.0)if __name__ == '__main__':    urllib.urlretrieve(url,file,reporthook)

读书人网 >perl python

热点推荐