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)