前面为抖音解析接口增加了头条视频支持,当时猜测字节跳动旗下的短视频解析应该都是一个套路,后来发现好像西瓜视频不是这样,所以本站的抖音无水印解析目前是暂不支持西瓜视频解析的。
西瓜视频采用与哔哩哔哩一样音视频分离的方式,所以是没办法直接获取带声音的视频的,不过通过ffmpeg可以合并,也可以通过视频剪辑软件比如剪映、PR、AE等进行合并。下面看看如何获取西瓜视频的音视频资源吧。
直接访问任意一个西瓜视频地址,可以通过网页播放视频,通过查看源码可以看到,网页中带有视频的相关信息,如下:
其中可以找到vid,这个vid是不是跟抖音头条视频很像呢?由于不知道接口,这个东西暂时没用。在这段信息中,音视频地址就在其中,只不过被Base64编码了,我们可以直接在控制台中执行以下js代码得到解码后的地址。
视频
复制
window.atob(window._SSR_HYDRATED_DATA.anyVideo.gidInformation.packerData.video.videoResource.dash_120fps.dynamic_video.dynamic_video_list.pop().main_url);
音频
复制
window.atob(window._SSR_HYDRATED_DATA.anyVideo.gidInformation.packerData.video.videoResource.dash_120fps.dynamic_video.dynamic_audio_list.pop().main_url);
使用python获取
复制
# -*- coding: UTF-8 -*- import json import requests import base64 def xigua(url): headers = { "cookie": "ixigua-a-s=0; __ac_nonce=062711eef0074c53fd301; " "__ac_signature=_02B4Z6wo00f01ixJMjwAAIDDB8Np-ahvLqYsaTaAAOlxwFWsX1Khk-KvFlM1N2JBoEUa-eVrLxEyF" ".bLdz61qjeQ-CTdvApqa7NKn7HTvbu1Nktww-QaXyO3gNQSkIdrfp3XdUkGrdCwrQKpea; " "MONITOR_WEB_ID=6364cae8-2aa7-4531-9a30-1b98b0ee7596; " "ttwid=1%7CTOw3V-1qPgQfcCT4S0Hhey26Q4PJq9J6nGaLq6GMe14%7C1651580656" "%7C48653bc0c5afd31f1a919f9bd17a80173a1ea69d96b23359b103c4f078ef969b; support_webp=true; " "support_avif=true; _tea_utm_cache_1300=undefined", "Referer": "https://www.ixigua.com", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/86.0.4240.75 Safari/537.36" } resp = requests.get(url=url,headers=headers) resp.encoding = 'utf-8' if resp.status_code == 200: res_html = resp.text if 'pseries_more_v2' not in url: json_str = re.findall('window._SSR_HYDRATED_DATA=(.*?)</script>', res_html)[0] json_str = json_str.replace('undefined', 'null') json_data = json.loads(json_str) video_url = \ json_data['anyVideo']['gidInformation']['packerData']['video']['videoResource']['dash'][ 'dynamic_video'][ 'dynamic_video_list'][-1]['main_url'] audio_url = \ json_data['anyVideo']['gidInformation']['packerData']['video']['videoResource']['dash'][ 'dynamic_video'][ 'dynamic_audio_list'][-1]['main_url'] title = json_data['anyVideo']['gidInformation']['packerData']['video']['title'] title = re.sub(r"[\/\\\:\*\?\"\<\>\|]", "_", title).replace(" ", "") video_url = base64.b64decode(video_url).decode() audio_url = base64.b64decode(audio_url).decode() print(video_url) print(audio_url) print(title) else: json_data = json.loads(res_html) for item in json_data['data']: title = item['title'] # backup_url_1 video_url = item['preloadVideoResource']['dynamic_video']['dynamic_video_list'][-1][ 'backup_url_1'] audio_url = item['preloadVideoResource']['dynamic_video']['dynamic_audio_list'][-1][ 'backup_url_1'] video_url = base64.b64decode(video_url).decode() audio_url = base64.b64decode(audio_url).decode() title = re.sub(r"[\/\\\:\*\?\"\<\>\|]", "_", title).replace(" ", "") print(video_url) print(audio_url) print(title) xigua(url)
python需要对齐,上面代码被定格处理了,所以自行空格吧。
评论 (4)
File "d:/pythonlearn/xigua2.py", line 48, in xigua
json_str = re.findall('window._SSR_HYDRATED_DATA=(.*?)', res_html)[0]
IndexError: list index out of range
看看这个就不能
是不是
https://www.ixigua.com/7138736152567251470?logTag=a1a9981d4b0d7cbc9cc7
window._SSR_HYDRATED_DATA.anyVideo.gidInformation.packerData.video.videoResource.normal.video_list.video_3.main_url
这个提交评论能多个CTRL+ENTER的快捷键就好了