分享一下我自己整理的代碼,改兩個參數就可使用(掃描下方二維碼獲取python學習資料) import requests import time headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebK ...
分享一下我自己整理的代碼,改兩個參數就可使用(掃描下方二維碼獲取python學習資料)
import requests import time headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36' } movie_url = '在這裡輸入視頻地址,例如:http://www.***********.mp4' movie_name = '視頻標題' downsize = 0 print('開始下載') startTime = time.time() req = requests.get(movie_url, headers=headers, stream=True, verify=False) with(open(movie_name+'.mp4', 'wb')) as f: for chunk in req.iter_content(chunk_size=10000): if chunk: f.write(chunk) downsize += len(chunk) line = 'downloading %d KB/s - %.2f MB, 共 %.2f MB' line = line % ( downsize / 1024 / (time.time() - startTime), downsize / 1024 / 1024, downsize / 1024 / 1024) print(line)