哈喽兄弟们,抖音现在有JS加密,以前的方法爬不了饿了,今天来实现一下某音短视频的JS逆向解析。


知识点

动态数据抓包`在这里插入代码片`
requests发送请求
X-Bogus参数逆向

环境模块

python3.8运行代码
pycharm2022.3辅助敲代码
requestspipinstallrequests安装

源码

获取数据部分

import requestsimport execjs  ctx = execjs.compile(open('xb.js', mode='r', encoding='utf-8').read())headers = {    'referer': 'https://www.douyin.com/user/MS4wLjABAAAAqsOmrExIsJbZ2b0QLzytzAhAFbJUROH72_yVYM7Zq8E?vid=7273024102460362047',    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',}arg1 = 'device_platform=webapp&aid=6383&channel=channel_pc_web&sec_user_id=MS4wLjABAAAAqsOmrExIsJbZ2b0QLzytzAhAFbJUROH72_yVYM7Zq8E&max_cursor=1690869936000&locate_item_id=7273024102460362047&locate_query=false&show_live_replay_strategy=1&need_time_list=1&time_list_query=0&count=18&publish_video_strategy_type=2&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1920&screen_height=1080&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=116.0.0.0&browser_online=true&engine_name=Blink&engine_version=116.0.0.0&os_name=Windows&os_version=10&cpu_core_num=6&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=0&webid=7206570248416773684&msToken=kuJ7VXEum5t8MRJsb-EWiKneHuMabLt_Xmvzqjv7Tl92qzTPYaHkfIMCn9ndAkA39d7QfcI57AU353tQuNpAnxbsgxSEXN6KR4Du5bRKUrivq2hBvPiEPaFyW0xyaMc='url = 'https://www.douyin.com/aweme/v1/web/aweme/post/?'xb = arg1 + '&X-Bogus=' + ctx.call('window.siyue111', arg1)url += xbprint(url)response = requests.get(url, headers=headers)json_data = response.json()aweme_list = json_data['aweme_list']for aweme in aweme_list:    desc = aweme['desc']    video_url = aweme['video']['play_addr']['url_list'][0]    # JS解密部分太长了,我直接打包了,还录制了详细讲解的视频。    # 都放在这个扣裙了 592539176    print(desc, video_url)

JS解密部分太长了,我直接打包了,还录制了详细讲解的视频。


好了,今天的分享就到这里结束了,下次见!