nodejs 某音douyin网页端搜索接口及x_bogus、a_bogus(包含完整源码)(2024-06-13)

2024-06-14 23:04

本文主要是介绍nodejs 某音douyin网页端搜索接口及x_bogus、a_bogus(包含完整源码)(2024-06-13),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前言


    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}`;elseapi_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调用搜索接口返回数据)

这篇关于nodejs 某音douyin网页端搜索接口及x_bogus、a_bogus(包含完整源码)(2024-06-13)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1061749

相关文章

Java调用C++动态库超详细步骤讲解(附源码)

《Java调用C++动态库超详细步骤讲解(附源码)》C语言因其高效和接近硬件的特性,时常会被用在性能要求较高或者需要直接操作硬件的场合,:本文主要介绍Java调用C++动态库的相关资料,文中通过代... 目录一、直接调用C++库第一步:动态库生成(vs2017+qt5.12.10)第二步:Java调用C++

在React中引入Tailwind CSS的完整指南

《在React中引入TailwindCSS的完整指南》在现代前端开发中,使用UI库可以显著提高开发效率,TailwindCSS是一个功能类优先的CSS框架,本文将详细介绍如何在Reac... 目录前言一、Tailwind css 简介二、创建 React 项目使用 Create React App 创建项目

go中空接口的具体使用

《go中空接口的具体使用》空接口是一种特殊的接口类型,它不包含任何方法,本文主要介绍了go中空接口的具体使用,具有一定的参考价值,感兴趣的可以了解一下... 目录接口-空接口1. 什么是空接口?2. 如何使用空接口?第一,第二,第三,3. 空接口几个要注意的坑坑1:坑2:坑3:接口-空接口1. 什么是空接

Python实现无痛修改第三方库源码的方法详解

《Python实现无痛修改第三方库源码的方法详解》很多时候,我们下载的第三方库是不会有需求不满足的情况,但也有极少的情况,第三方库没有兼顾到需求,本文将介绍几个修改源码的操作,大家可以根据需求进行选择... 目录需求不符合模拟示例 1. 修改源文件2. 继承修改3. 猴子补丁4. 追踪局部变量需求不符合很

使用Python实现获取网页指定内容

《使用Python实现获取网页指定内容》在当今互联网时代,网页数据抓取是一项非常重要的技能,本文将带你从零开始学习如何使用Python获取网页中的指定内容,希望对大家有所帮助... 目录引言1. 网页抓取的基本概念2. python中的网页抓取库3. 安装必要的库4. 发送HTTP请求并获取网页内容5. 解

Python使用DrissionPage中ChromiumPage进行自动化网页操作

《Python使用DrissionPage中ChromiumPage进行自动化网页操作》DrissionPage作为一款轻量级且功能强大的浏览器自动化库,为开发者提供了丰富的功能支持,本文将使用Dri... 目录前言一、ChromiumPage基础操作1.初始化Drission 和 ChromiumPage

MySQL中慢SQL优化方法的完整指南

《MySQL中慢SQL优化方法的完整指南》当数据库响应时间超过500ms时,系统将面临三大灾难链式反应,所以本文将为大家介绍一下MySQL中慢SQL优化的常用方法,有需要的小伙伴可以了解下... 目录一、慢SQL的致命影响二、精准定位问题SQL1. 启用慢查询日志2. 诊断黄金三件套三、六大核心优化方案方案

Spring 中 BeanFactoryPostProcessor 的作用和示例源码分析

《Spring中BeanFactoryPostProcessor的作用和示例源码分析》Spring的BeanFactoryPostProcessor是容器初始化的扩展接口,允许在Bean实例化前... 目录一、概览1. 核心定位2. 核心功能详解3. 关键特性二、Spring 内置的 BeanFactory

如何用java对接微信小程序下单后的发货接口

《如何用java对接微信小程序下单后的发货接口》:本文主要介绍在微信小程序后台实现发货通知的步骤,包括获取Access_token、使用RestTemplate调用发货接口、处理AccessTok... 目录配置参数 调用代码获取Access_token调用发货的接口类注意点总结配置参数 首先需要获取Ac

讯飞webapi语音识别接口调用示例代码(python)

《讯飞webapi语音识别接口调用示例代码(python)》:本文主要介绍如何使用Python3调用讯飞WebAPI语音识别接口,重点解决了在处理语音识别结果时判断是否为最后一帧的问题,通过运行代... 目录前言一、环境二、引入库三、代码实例四、运行结果五、总结前言基于python3 讯飞webAPI语音