【发布时间】:2013-04-23 12:48:12
【问题描述】:
此脚本从网站下载文件,在大文件中存在问题,因为丢失数据包导致停止下载...这是代码:
def download(self):
adres = r"http://example.com/100_MbFile.zip"
local = adres.split('/')[-1].split('#')[0].split('?')[0]
try:
print "Przygotowanie do zapisania pliku " + local
u = urllib2.urlopen(adres)
f = open(local, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print("Downloading: {0} Bytes: {1}".format(adres, file_size))
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
p = float(file_size_dl) / file_size
status = r"{0} [{1:.2%}]".format(file_size_dl, p)
status = status + chr(8)*(len(status)+1)
sys.stdout.write(status)
if file_size_dl == file_size:
f.close()
知道如何下载大文件吗?
【问题讨论】:
-
你查看过这个帖子吗? stackoverflow.com/questions/1979435/…