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)
Original: https://www.cnblogs.com/lvye001/p/16489241.html
Author: lvye001
Title: python 抓取视频并显示下载进度
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/597006/
转载文章受原作者版权保护。转载请注明原作者出处!