前言
x_bogus或a_bogus算法大概是对数据、ua、时间戳、浏览器的几个指纹进行计算,拿到一个110位大数组,然后转字符,在头部再添加十二位随机字符,再进行魔改的base64加密。
问:抖音的x_bogus、a_bogus值有什么用?
1.抖音所有数据的校验都离不开x_bogus、a_bogus。
2.抖音作为最大的短视频平台他的数据是十分多且有用的。
3.获取批量抖音的数据,例如评论、无水印视频、弹幕监听、直播间抢货等。
在浏览器按f12可找到搜索接口地址。
一、接口地址:
api_url=`https://www.douyin.com/aweme/v1/web/search/item/?device_platform=webapp&aid=6383&channel=channel_pc_web&search_channel=aweme_video_web&sort_type=${sort_type}&publish_time=${publish_time}&keyword=${keyword}&search_source=switch_tab&query_correct_type=1&is_filter_search=${is_filter_search}&from_group_id=&offset=${offset}&count=10&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1536&screen_height=864&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=114.0.0.0&browser_online=true&engine_name=Blink&engine_version=114.0.0.0&os_name=Windows&os_version=10&cpu_core_num=8&device_memory=8&platform=PC&downlink=0.3&effective_type=2g&round_trip_time=1600&webid=7119735414450456103&msToken=${msToken}`;
二、参数说明
0、搜索结果按页返回,每页有10个视频
1、offset
搜索分页的偏移;0为第一页,10为二页,20第三页。
2、search_id
第二页还需要带上search_id参数;search_id由上一页返回。
3、sort_type
搜索结果排序
排序说明:
综合排序
sort_type=0
最新发布
sort_type=2
最多点赞
sort_type=1
4、publish_time
按发布时间过滤条件
不限
publish_time=0
一天内
publish_time=1
一周内
publish_time=7
半年内
publish_time=182
三、完整源代码
//----------------------------------------------模块初始化----------------------------------------------------
const User_Agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36";
const fs = require("fs");
const cookie= fs.readFileSync("./cookie.txt").toString('utf8');
//console.log(cookie);
let msToken="";
const https = require('node:https');
exports.get_search_data=get_search_data;
//----------------------------------------------调用模块初始化----------------------------------------------------
//技术支持:byc6352或metabycf 39848872 telegram:byc01
const m_x_bogus = require('./x_bogus.js');
//-------------------------------------------------------------------------------------------------------------
async function get_search_data(keyword,offset,search_id,sort_type,publish_time) {
try {
msToken=getCookie("msToken");
if(keyword===undefined || offset===undefined){
return;
}
keyword=encodeURIComponent(keyword);
if(offset>0 && search_id===undefined){
return;
}
let is_filter_search=0;
if(sort_type>0 || publish_time>0)is_filter_search=1;
//-----------------------------------------------------------------------------------------------------
let api_url="";
if(offset===0)
api_url=`https://www.douyin.com/aweme/v1/web/search/item/?device_platform=webapp&aid=6383&channel=channel_pc_web&search_channel=aweme_video_web&sort_type=${sort_type}&publish_time=${publish_time}&keyword=${keyword}&search_source=switch_tab&query_correct_type=1&is_filter_search=${is_filter_search}&from_group_id=&offset=${offset}&count=10&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1536&screen_height=864&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=114.0.0.0&browser_online=true&engine_name=Blink&engine_version=114.0.0.0&os_name=Windows&os_version=10&cpu_core_num=8&device_memory=8&platform=PC&downlink=0.3&effective_type=2g&round_trip_time=1600&webid=7119735414450456103&msToken=${msToken}`;
else
api_url=`https://www.douyin.com/aweme/v1/web/search/item/?device_platform=webapp&aid=6383&channel=channel_pc_web&search_channel=aweme_video_web&sort_type=${sort_type}&publish_time=${publish_time}&keyword=${keyword}&search_source=switch_tab&query_correct_type=1&is_filter_search=${is_filter_search}&from_group_id=&offset=${offset}&search_id=${search_id}&count=10&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1536&screen_height=864&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=114.0.0.0&browser_online=true&engine_name=Blink&engine_version=114.0.0.0&os_name=Windows&os_version=10&cpu_core_num=8&device_memory=8&platform=PC&downlink=0.3&effective_type=2g&round_trip_time=1600&webid=7119735414450456103&msToken=${msToken}`;
let api_url_bogus=m_x_bogus.get_x_bogus(User_Agent,api_url);
let refer_url=`https://www.douyin.com/search/${keyword}?publish_time=${publish_time}&sort_type=${sort_type}&source=tab_search&type=video`;
let path=api_url_bogus.replace("https://www.douyin.com","");
const options = {
hostname: 'www.douyin.com',
port: 443,
path: path,
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept':'application/json',
'Referer': refer_url,
'User-Agent': User_Agent,
'Cookie':cookie,
},
};
//console.log(api_url_bogus);
const req = https.request(api_url_bogus,options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
var body="";
res.on('data', (chunk) => {
body+=chunk;
});
res.on('end', () => {
console.log(body.length);
console.log(body);
});
});
req.on('error', (e) => {
console.error(`problem with request: ${e.message}`);
});
req.end();
}catch (e){
console.error(`problem with get_search_data: ${e.message}`);
}
}
function getCookie(cname)
{
let name = cname + "=";
//var cc=cookie;
//var ca = cc.split(';');
let ca = cookie.split(";");
for(var i=0; i<ca.length; i++)
{
var c = ca[i].trim();
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
}
return "";
}
//------------------------------------------------test----------------------------------------
get_search_data("易梦玲",0,undefined,0,0);
四、运行结果(截取一部分)
其中"logid":"202406131910573707A1B160EA8C199E6D"为下一页的search_id。
STATUS: 200
HEADERS: {"server":"Tengine","content-type":"application/json; charset=utf-8","content-length":"531430","connection":"close","date":"Thu, 13 Jun 2024 11:10:59 GMT","vary":"Accept-E
ncoding","x-tt-logid":"202406131910573707A1B160EA8C199E6D","bd-tt-error-code":"0","tt_stable":"1","status_code":"0","x-envoy-response-flags":"-","rip":"[fdbd:dc01:a:226::103]:9891"
,"to-cluster":"default","to-idc":"lf","x-ms-token":"vfLq1X_9QfRtlkT8HvKWLj2_qQq22ISgZ9L26kVcjKszk4XJUK4LTuiJkAHpJOwxTIfp6I0Xi2tdqVVPMEniXuhcZ6nAs0fnXZIhgUnvXTXlWt6WNQnXqNw=","cooki
e_ttwidinfo_webid":"7119735414450456103","x-janus-info":"rDbyyBfD-5ujgb_-Rm2AvHfE6XHmPkRGTpZk5vIe2rQXmYBeqJPNn5-CWYn_hWOD8HiRBLTA52Ec7mlGA-wzTsVmRgFBM5YujJwlHu8rJO-xRks7hiAZPGX9_7d
PARQUV_d4lyQeXaxY9yz_MuMPFz-ziJ-JU9WUAq2dnODwD7e24YYCQZ89r2O3IgzuF3emnCE1qFGFlwEUQnhiid8ttWenfJccISYM8ZjfHrqqz5FS4xvYVy5U58JrWWEZ_f5FkyAcT81A8Xb2IauMU3Y1AP8sLloOOMQI","set-cookie":
["msToken=vfLq1X_9QfRtlkT8HvKWLj2_qQq22ISgZ9L26kVcjKszk4XJUK4LTuiJkAHpJOwxTIfp6I0Xi2tdqVVPMEniXuhcZ6nAs0fnXZIhgUnvXTXlWt6WNQnXqNw=; expires=Thu, 20 Jun 2024 11:10:57 GMT; domain=do
uyin.com; path=/; secure; SameSite=None"],"strict-transport-security":"max-age=31536000; includeSubDomains; preload","access-control-allow-credentials":"true","server-timing":"inne
r; dur=1156, cdn-cache;desc=MISS,edge;dur=0,origin;dur=1207","x-tt-trace-host":"01f5a7f74fb1f6a9381bdfd3524d31f903fb2661dd81165567ee8841b0f493a95e97ae933aaf2e119127ed3fe917d68f1231
1bd9a07ee6257497b6f8c11d2797a3c757c5198c00f4d88e6a94558d76e4ae1144ec7aa9620815dc08830db7c0195e","x-tt-trace-tag":"id=03;cdn-cache=miss;type=dyn","x-tt-trace-id":"00-240613191057370
7A1B160EA8C199E6D-237EFF9838FEB7F4-00","via":"live4.cn6822[1207,0]","timing-allow-origin":"*","eagleid":"b6f7ecb417182770579434102e"}
523342
{"status_code":0,"aweme_list":null,"has_more":1,"cursor":10,"guide_search_words":[{"id":"6548652907695183112","word":"路人视角","type":"recom","query_id":"6581242608947844356","att
ached_text":null},{"id":"6585020614170400004","word":"马思唯","type":"recom","query_id":"6581242608947844356","attached_text":null},{"id":"6598250693897770253","word":"壁纸","type"
:"recom","query_id":"6581242608947844356","attached_text":null},{"id":"6537235052961469700","word":"手势舞","type":"recom","query_id":"6581242608947844356","attached_text":null},{"
id":"6543530651927188740","word":"方圆","type":"recom","query_id":"6581242608947844356","attached_text":null},{"id":"6818788051146282254","word":"一拍即合的我们","type":"recom","qu
ery_id":"6581242608947844356","attached_text":null},{"id":"6538978456762324227","word":"素颜","type":"recom","query_id":"6581242608947844356","attached_text":null},{"id":"652757201
8743743752","word":"虞书欣","type":"recom","query_id":"6581242608947844356","attached_text":null},{"id":"6543531834616059149","word":"仿妆","type":"recom","query_id":"6581242608947
844356","attached_text":null},{"id":"6537292146192438541","word":"跳舞","type":"recom","query_id":"6581242608947844356","attached_text":null},{"id":"6595888160872338695","word":"同
款","type":"recom","query_id":"6581242608947844356","attached_text":null},{"id":"6598867558164600071","word":"gq红毯","type":"recom","query_id":"6581242608947844356","attached_text
":null},{"id":"6537253792889443597","word":"综艺","type":"recom","query_id":"6581242608947844356","attached_text":null}],"extra":{"now":1718277059000,"logid":"202406131910573707A1B
160EA8C199E6D","fatal_item_ids":[],"search_request_id":""},"log_pb":{"impr_id":"202406131910573707A1B160EA8C199E6D"},"backtrace":"f8zSdzdPBhl57DL+Qz8rLw==","data":[{"type":1,"aweme
_info":{"aweme_id":"7377673797048012083","desc":"穿你想穿的,吃你想吃的\n#毕业了出去玩就这么穿","create_time":1717748546,"author":{"uid":"58878877918","nickname":"易梦玲","avatar_t
五、调试环境
(图1 nodejs调用搜索接口返回数据)