爬虫学习分享Python下载mp4文件(源码)

 给大家分享一个能直接下载mp4的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)

爬虫学习分享Python下载mp4文件(源码)_第1张图片

关注获取更多学习资料~ 

 

你可能感兴趣的:(爬虫)