【笔记】Python3实现下载进度条

前言

Python3通过tqdm实现requests的下载进度条

下载依赖

1
pip3 install tqdm

包含进度条的下载

<url>:资源下载路径
<file>:文件存储路径

1
2
3
4
5
6
7
8
9
response = requests.get(<url>, stream=True)
with open("<file>", "wb") as f:
for data in tqdm.tqdm(
iterable=response.iter_content(1024),
total=int(response.headers['Content-Length']) / 1024,
unit="k",
desc="描述"
):
f.write(data)

完成

参考文献

哔哩哔哩——小菲超努力呦