思路
https://weibo.com/tv/show/1034:5028532510982210?mid=5028533009124778
查看原地址,发现是由component接口post请求携带参数 获取的 需要增加cookie
代码
import requests
import re
index_url = 'https://weibo.com/tv/show/1034:5028532510982210?mid=5028533009124778'
vid = re.findall('show/1034:(.*?)\\?mid', index_url)[0]
# print(vid)
url = 'https://weibo.com/tv/api/component?page=%2Ftv%2Fshow%2F1034%3A' + vid
headers = {
'cookie': 'SINAGLOBAL=3560693377508.3193.1713855669164; _s_tentry=-; Apache=9755286762859.102.1714466966704; ULV=1714466966826:2:2:1:9755286762859.102.1714466966704:1713855669314; XSRF-TOKEN=KVYInRqkd3FtdBHDNdckWm2L; SUB=_2A25LNMR0DeRhGeNI4lMT-S7Kzz6IHXVoSFm8rDV8PUNbmtANLXj5kW9NSA860p7dTow29exd-1zv-hZxFn1Yp2ey; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WW8qZPBvUAbCSPcfg7N1Qew5JpX5KzhUgL.Fo-c1K2E1K5cShz2dJLoI0YLxKnL1KeL1-BLxK-L1hqLBo5LxK.LBo.LB.qLxKML1-2L1hBLxK-LBo5L12qLxK-L122LBK.LxKML1K5L1hqt; ALF=02_1717059877; WBPSESS=SUDPZ91ded6LcROjUSEdouFprLPD4fR6BJgU7TSlB_jLhYzoSypwOhEsfJtbBS0jTwLYPw_vxHNbH3sLFpMaVQV-F2CNHrbG44aGUWnzihHGKVficbxB78fIreoWiG8QH6l3eqclp1zar83xgk63cw==',
'referer': 'https://weibo.com/tv/show/1034:4694803645136959?mid=4694805986412000',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3880.400 QQBrowser/10.8.4554.400',
}
# data = {'data': '{"Component_Play_Playinfo":{"oid":"1034:4711490650046514"}}'}
data = {'data': '{"Component_Play_Playinfo":{"oid":"1034:' + vid + '"}}'}
json_data = requests.post(url=url, data=data, headers=headers).json()
# print(json_data)
video_url = 'http:' + json_data['data']['Component_Play_Playinfo']['urls']['高清 1080P']
print(video_url)
content = requests.get(url=video_url, headers=headers).content
with open('2.mp4', mode='wb') as f:
f.write(content)