利用python爬取新浪微博某高清视频
import requests
url = 'https://weibo.com/tv/api/component?page=%2Ftv%2Fshow%2F1034%3A4715681229504535'
#数据参数
data = {
'data':'{"Component_Play_Playinfo":{"oid":"1034:4715681229504535"}}'
}
#加伪装
headers = {
'cookie':'login_sid_t=3bd4769043d679698e4027abc68a19ad; cross_origin_proto=SSL; _s_tentry=www.google.com; TC-V-WEIBO-G0=35846f552801987f8c1e8f7cec0e2230; Apache=305749860309.5965.1640091510502; SINAGLOBAL=305749860309.5965.1640091510502; ULV=1640091510510:1:1:1:305749860309.5965.1640091510502:; _ga=GA1.2.1378508093.1640091516; _gid=GA1.2.372615198.1640091516; __gads=ID=ea526ea146392bd3:T=1640091521:S=ALNI_MarcDpRuUQD6MdIP19TotAVvfRz9Q; SUB=_2AkMWnUC6f8NxqwJRmfwRz2nga4VxyAvEieKgwbFhJRMxHRl-yT92qhIttRB6PR1uVT_FVT0v2Ylh1kdhjsMZHe78F85j; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9Whi3_-XlTniI0Q9CHPNBcRw; XSRF-TOKEN=CRf522iw92KxJQ1Tpw1uNDp-; wb_view_log=1536*8641.25; WBPSESS=2jFn3n4I-3CwFbURoTaQuz54etRSR1V_5EmTPl_IM5hVQVQm3Q5LsN1ihLxr7U02rgrDcIRz_twnIMCMeIwbzc_imlpCcz0uT9AXhEZmT4b84IumL3LaMyRlbF7yS87BOuf3wr-PhzLCjmRRFZixth4zJsXy9R34LeKzfrEfayM=; UOR=www.google.com,weibo.com,m.weibo.cn',
'referer':'https://weibo.com/tv/show/1034:4715681229504535?from=old_pc_videoshow',
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
}
json_data = requests.post(url=url,data=data,headers=headers,timeout=10).json()
video_url = "https:" + json_data['data']['Component_Play_Playinfo']['urls']['高清 720P']
print(video_url)
video_data = requests.get(video_url).content
with open("微博某视频.mp4",'wb') as f:
f.write(video_data)
print("下载完成!")