赞
踩
经常遇到下载的情况,简单记录一种~
Talk is cheap,show me the code!
- ###使用requests包
-
- import requests
- import os
-
- filename = 'temp.mp4'
- video_path = tar_folder + '/' + filename
-
- #建立目标文件夹
- if not os.path.exists(tar_folder):
- os.makedirs(tar_folder, exist_ok=True)
-
- #下载
- res = requests.get(url, stream=True)
- with open(video_path, 'wb') as f1:
- for chunk in res.iter_content(chunk_size=102400):
- f1.write(chunk)
-
有问题随时交流,欢迎一键三连~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。