目标网站:https://www.pearvideo.com/
# 爬取要求:1、用户输入视频页面的链接
# 2、把所对应页面的视频,下载下来,保存到本地
# “https://video.pearvideo.com/mp4/short/20220217/1645096543967-15827739-hd.mp4
# https://www.pearvideo.com/video_1748543
import requests
import re
# url = ‘ https://video.pearvideo.com/mp4/short/20220217/cont-1748543-15827739-hd.mp4
video = str(input(‘请输入视频页面的链接:’))
video1 = video.replace(‘www’,’video’)
n = re.findall(r”\d+.?\d*”,video1)
url = video1.replace(f’video{n}’,f’/mp4/short/20220217/cont-{n}-15827739-hd.mp4’)
print(url)
headers = {
‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36’,
‘Referer’: f’https://www.pearvideo.com/video
{n}’,
}
response = requests.get(url,headers=headers)
with open(‘b.mp4’, ‘wb’) as f:
f.write(response.content)