【防盗链】Python&&见招拆招处理

【防盗链】Python&&见招拆招处理,第1张

【防盗链】Python&&见招拆招处理 进入到某网站,查看页面源代码

查看请求

对比一下,突破点

处理防盗链

# 1.拿到contId
# 2.拿到videoStatus返回的json. -> srcUrl
# 3. srcUrl 里面的内容进行修整
# 4. 下载视频
import requests

# 拉取视频的网址 -> 进入到指定某个视频页面源码
url = "https://www.pearvideo.com/video_1514115"
contId = url.split("_")[1]


videoStatusUrl = f"https://www.pearvideo.com/videoStatus.jsp?contId={contId}&mrd=0.543370355350492"
headers = {
 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
 # 防盗链:溯源,当前本次请求的上一级是谁
 "Referer": url

}

resp = requests.get(videoStatusUrl,headers=headers)
dic = resp.json()
# print(dic)
srcUrl = dic['videoInfo']['videos']['srcUrl']
systemTime = dic['systemTime']
srcUrl = srcUrl.replace(systemTime,f"cont-{contId}")
# print(srcUrl)

# https://video.pearvideo.com/mp4/adshort/20190202/cont-1514115-13551715_adpkg-ad_hd.mp4
# https://video.pearvideo.com/mp4/adshort/20190202/cont-1514115-13551715_adpkg-ad_hd.mp4 提取对比
# https://video.pearvideo.com/mp4/adshort/20190202/1643725981732-13551715_adpkg-ad_hd.mp4

# 下载视频
with open("PearFilm.mp4",mode="wb") as f:
 f.write(requests.get(srcUrl).content)

print("提取视频完毕")

运行结果

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5721320.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-18
下一篇 2022-12-18

发表评论

登录后才能评论

评论列表(0条)

保存