import requests
from lxml import etree
import os
# 拿到视频地址url
url = 'https://www.pearvideo.com/video_1160135'
# 提取url中的cont_id,后面用
cont_id = url.split('_')[1]
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
"Referer": url
}
Request_URL = f'https://www.pearvideo.com/videoStatus.jsp?contId={cont_id}&mrd=0.5294709840745704'
response = requests.get(url=Request_URL, headers=headers)
# 这里返回的数据以json格式读取,方便拿取里面的连接
dic = response.json()
src = dic["videoInfo"]["videos"]["srcUrl"]
system_time = dic["systemTime"]
# 视频的播放地址
src = src.replace(system_time, f"cont-{cont_id}")
# print(src)
# 保存视频
with open("1.mp4", 'wb') as f:
f.write(requests.get(src).content)
f.close()
标签:视频,cont,src,python,08,url,import,id From: https://www.cnblogs.com/shuxi/p/17220227.html