|
|
发表于 2018-6-7 11:28:23
|
显示全部楼层
用requests模块,类似这样:
- with closing(requests.get(download_url, headers=self.headers, stream=True)) as response:
- chunk_size = 1024
- content_size = int(response.headers['content-length'])
- if response.status_code == 200:
- sys.stdout.write('[File Size]: %0.2f MB\n' % (content_size/chunk_size/1024))
- with open(path, 'wb') as f:
- for data in response.iter_content(chunk_size=chunk_size):
- f.write(data)
- size += len(data)
- f.flush()
- sys.stdout.write('[Progress]: %0.2f%%' % float(size/content_size*100) + '\r')
- sys.stdout.flush()
复制代码
修改chunk_size加快速度。
- from contextlib import closing
复制代码 |
|