爬取具有防盗链的视频网站视频

#传过来的json中的数据链接https://video.pearvideo.com/mp4/short/20220427/1651201342168-15869965-hd.mp4
#页面html中的<video webkit-playsinline="" playsinline="" x-webkit-airplay="" style="width: 100%; height: 100%;"
# src="https://video.pearvideo.com/mp4/short/20220427/cont-1749065-15869965-hd.mp4"></video>
#1,拿到countid
#2,拿到视频链接地址json

#5srcurl里面内容进行修整
#4下载视频
import requests
from lxml import etree
name=input("请输入梨视频链接:")
url=name
header={
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36",
    #防盗链寻找来源
    "Referer": url

    }
res1=requests.get((url))
html=etree.HTML(res1.text)
title=html.xpath("/html/body/div[2]/div[1]/div[1]/div[1]/div[2]/img/@alt")[0]
print(title)
counid=url.split("_")[1]
videolink=f"https://www.pearvideo.com/videoStatus.jsp?contId={counid}&mrd=0.864035799651441"
res=requests.get(videolink,headers=header)
print(res.text)
a=res.json()['videoInfo']['videos']['srcUrl']
time=res.json()["systemTime"]
print(a)
link=a.replace(time,f"cont-{counid}")
print(link)
#https://video.pearvideo.com/mp4/short/20220427/cont-1749065-15869965-hd.mp4
#https://video.pearvideo.com/mp4/short/20220427/count-1749065-15869965-hd.mp4
with open (f"梨视频/{title}.mp4",mode="wb") as f:
    f.write(requests.get(link).content)

 

posted @ 2022-04-30 16:56  凋零_(  阅读(98)  评论(0编辑  收藏  举报