request 模块 请求url保存视频demo

#!/usr/bin/env python3
# coding=utf-8
#from urllib.request import urlopen;
from urllib import request;
import ssl;
ssl._create_default_https_context = ssl._create_unverified_context


url='http://alimov2.a.yximgs.com/upic/2018/07/08/17/BMjAxODA3MDgxNzA1NTBfNzM4ODc5OV83MDI5MTQzMTgwXzJfMw==_hd3_B1ccb46bbfa6516524a1bccefe7854fc7.mp4?tag=1-1531137529-h-0-zz9d4xbdzq-6cfd37bf20f35eb8';
req=request.Request(url);


req.add_header('User-Agent','Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36');
response=request.urlopen(req).read();


with open('dd.mp4','wb') as f:
f.write(response);

你可能感兴趣的:(python)