如果我们想要看抖音的数据,在抓包的时候,会发现有一个xgorgon参数,在请求接口的时候,只需要在请求头携带xgorgon参数,就能获得响应后的数据。
目前抖音的xgorgon0404算法已经还原了,
下面是一个请求的demo。代码如下:
from urllib.parse import quote,urlparse, urlencode
import requests
import json
from douyin.parse.Xg_0404 import get_xg0404
from douyin.parse.xgorgon0408 import get_xgorgon
data_url = "https://api5-normal-c-lf.amemv.com/aweme/v1/mix/list/?user_id=2613650662&sec_user_id=MS4wLjABAAAAYzvfhHu8gZaQ8Z0F9MGpjokYlNp13_KdW6eD6OLvaYg&count=15&cursor=0&manifest_version_code=130101&_rticket=1635417096396&app_type=normal&iid=1117548593032600&channel=tengxun_new&device_type=ONEPLUS+A3000&language=zh&cpu_support64=true&host_abi=armeabi-v7a&uuid=860046036819474&resolution=1080*1920&openudid=d61b4ef3d4597061&update_version_code=13109900&cdid=47d5680a-2ddb-456b-aec7-48aca01a24b3&appTheme=dark&os_api=28&mac_address=C0%3AEE%3AFB%3AD6%3AC3%3A97&dpi=420&ac=wifi&device_id=48290276163&os_version=9&version_code=130100&app_name=aweme&version_name=13.1.0&device_brand=OnePlus&ssmix=a&device_platform=android&aid=1128&ts=1635417095"
xgorgon = get_xg0404(data_url)
print(xgorgon)
headers = {
"user-agent": "com.ss.android.ugc.aweme/130101 (Linux; U; Android 9; zh_CN; ONEPLUS A3000; Build/PKQ1.181203.001; Cronet/TTNetVersion:414feb46 2020-09-08 QuicVersion:7aee791b 2020-06-05)",
'X-Gorgon': xgorgon.get('X-Gorgon'),
'X-Khronos': xgorgon.get('X-Khronos'),
'X-SS-REQ-TICKET':xgorgon.get('_rticket'),
'Connection': 'Keep-Alive',
}
response = requests.get(data_url, headers=headers)
print(response.status_code)
print(response.text)
运行后的结果如下:
{'X-Gorgon': '0404d0e400011b6ea7cd1704a5760372721ccf34c4725a604c1c', 'X-Khronos': '1635417272', '_rticket': '1635417272385'}
200
{"total":0,"extra":{"now":1635417272000,"fatal_item_ids":[],"logid":"202110281834320102100430220E07BB7B"},"log_pb":{"impr_id":"202110281834320102100430220E07BB7B"},"mix_infos":[{"cover_url":{"url_list":["https://p3-sign.douyinpic.com/obj/tos-cn-i-0813/e164ad83006c4e169128edb4da5ace4e?x-expires=1635436800&x-signature=TGzpp9icwUUAV%2FmVZQSSAEMGHTo%3D&from=4080365293","https://p9-sign.douyinpic.com/obj/tos-cn-i-0813/e164ad83006c4e169128edb4da5ace4e?x-expires=1635436800&x-signature=8DHG4%2FOdv3bVA%2Fnj0FuT9Jjhdss%3D&from=4080365293","https://p26-sign.douyinpic.com/obj/tos-cn-i-0813/e164ad83006c4e169128edb4da5ace4e?x-expires=1635436800&x-signature=vBgC%2B05QCEKBx%2FxmH71LTrY%2FNZw%3D&from=4080365293"],"width":720,"height":720,"uri":"tos-cn-i-0813/e164ad83006c4e169128edb4da5ace4e"},"status":{"status":2,"is_collected":0},"statis":{"play_vv":20587246,"collect_vv":4407,"current_episode":0,"updated_to_episode":12},"desc":"活着和生活只在一食之间,6月15日起,每周一晚6点,美食微综艺《隐藏的食光》上线。跟柳岩姐姐一起用便利店的简单食材炮制隐藏的美食料理!","extra":"","share_info":{"share_title_other":"","share_desc_info":"这么有趣的合集,不能只有我一个人知道吧","share_url":"https://www.iesdouyin.com/share/mix/detail/6837471117364430862/?schema_type=24&object_id=6837471117364430862","share_weibo_desc":"这么有趣的合集,不能只有我一个人知道吧","share_desc":"在抖音,记录美好生活","share_title":"这么有趣的合集,不能只有我一个人知道吧","share_title_myself":""},"mix_id":"6837471117364430862","author":{"google_account":"","aweme_control":{"can_forward":true,"can_share":true,"can_comment":true,"can_show_comment":true},