需要使用第三发包 tqdm
安装
pip install tqdm
效果展示
简单文件下载代码
import requests
from tqdm import tqdm
def download(link:str):
"""下载文件"""
response = requests.get(link, stream=True)
response.raise_for_status()
file = link.split("/")[-1]
total = int(response.headers.get('content-length', 0))
with open(file, 'wb') as f, tqdm(
desc=file,
total=total,
unit='iB',
unit_scale=True,
unit_divisor=1024,
) as bar:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
size = f.write(chunk)
bar.update(size)
return file
if __name__ == '__main__':
link = ''
download(link)
标签:提醒,tqdm,file,chunk,link,进度,__,response,下载
From: https://www.cnblogs.com/yimeimanong/p/17438229.html