【发布时间】:2019-05-28 06:29:48
【问题描述】:
我想用 tqdm 添加一个下载进度条。问题是它向我展示了这个:
0%| | 0/11535.92578125 [00:00<?, ?KB/s]
它会下载文件而不显示任何进度。这是我的代码:
s = requests.Session()
r = s.post(url, login_data)
response = s.get(link_to_pdf, stream=True)
total_size = int(response.headers['content-length'])
# download the pdf
print(pdf_filename)
with open(pdf_filename + '.pdf', 'wb') as f:
for data in tqdm(iterable=response.iter_content(chunk_size=chunk_size), total=total_size/chunk_size, unit='KB'):
f.write(response.content)
【问题讨论】:
标签: python python-3.x tqdm