import os import requests from tqdm import tqdm VIDEO_PATH = r'videos' def download(url,fname): # 用流stream的方式获取url的数据 resp = requests.get(url, stream=True) total = int(resp.headers.get('content-length', 0)) with open(fname, 'wb') as file, tqdm( desc=fname, total=total, unit='iB', unit_scale=True, unit_divisor=1024, ) as bar: for data in resp.iter_content(chunk_size=1024): size = file.write(data) bar.update(size) if __name__ == "__main__": # 下载文件,并传入文件名 with open('gezhilundao.txt','r')as f: datas = f.readlines() for i in datas: url = i.strip() video_name = url.split('/')[-1] video_full_path = os.path.join(VIDEO_PATH,video_name) download(url, video_full_path)
原创文章,作者:6024010,如若转载,请注明出处:https://blog.ytso.com/275152.html