相关:https://blog.csdn.net/chenchen5152/article/details/122469705
import requests
from tqdm import tqdm
def download_file(url, file_pname):
"""
url: file url
file_pname: file save path
chunk_size: chunk size
"""
# 用流stream的方式获取url的数据
req = requests.get(url, stream = True)
# 获取文件长度,初始为0
total = int(req.headers.get('content-length', 0))
with open(file_pname, 'wb') as file, tqdm(
desc = file_pname,
total = total,
unit = 'iB',
unit_scale = True,
unit_divisor = 1024
) as bar:
for data in req.iter_content(chunk_size = 1024):
size = file.write(data)
bar.update(size)
file.close()
download_file('https://mirrors.tuna.tsinghua.edu.cn/Adoptium/19/jdk/arm/linux/OpenJDK19U-jdk_arm_linux_hotspot_19.0.2_7.tar.gz', 'failed_packages.txt')