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

相关文章

使用Python创建一个功能完整的Windows风格计算器程序

《使用Python创建一个功能完整的Windows风格计算器程序》:本文主要介绍如何使用Python和Tkinter创建一个功能完整的Windows风格计算器程序,包括基本运算、高级科学计算(如三... 目录python实现Windows系统计算器程序(含高级功能)1. 使用Tkinter实现基础计算器2.

Android实现定时任务的几种方式汇总(附源码)

《Android实现定时任务的几种方式汇总(附源码)》在Android应用中,定时任务(ScheduledTask)的需求几乎无处不在:从定时刷新数据、定时备份、定时推送通知,到夜间静默下载、循环执行... 目录一、项目介绍1. 背景与意义二、相关基础知识与系统约束三、方案一:Handler.postDel

一文教你Python如何快速精准抓取网页数据

《一文教你Python如何快速精准抓取网页数据》这篇文章主要为大家详细介绍了如何利用Python实现快速精准抓取网页数据,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录1. 准备工作2. 基础爬虫实现3. 高级功能扩展3.1 抓取文章详情3.2 保存数据到文件4. 完整示例

Java controller接口出入参时间序列化转换操作方法(两种)

《Javacontroller接口出入参时间序列化转换操作方法(两种)》:本文主要介绍Javacontroller接口出入参时间序列化转换操作方法,本文给大家列举两种简单方法,感兴趣的朋友一起看... 目录方式一、使用注解方式二、统一配置场景:在controller编写的接口,在前后端交互过程中一般都会涉及

SpringBoot整合OpenFeign的完整指南

《SpringBoot整合OpenFeign的完整指南》OpenFeign是由Netflix开发的一个声明式Web服务客户端,它使得编写HTTP客户端变得更加简单,本文为大家介绍了SpringBoot... 目录什么是OpenFeign环境准备创建 Spring Boot 项目添加依赖启用 OpenFeig

python获取网页表格的多种方法汇总

《python获取网页表格的多种方法汇总》我们在网页上看到很多的表格,如果要获取里面的数据或者转化成其他格式,就需要将表格获取下来并进行整理,在Python中,获取网页表格的方法有多种,下面就跟随小编... 目录1. 使用Pandas的read_html2. 使用BeautifulSoup和pandas3.

usb接口驱动异常问题常用解决方案

《usb接口驱动异常问题常用解决方案》当遇到USB接口驱动异常时,可以通过多种方法来解决,其中主要就包括重装USB控制器、禁用USB选择性暂停设置、更新或安装新的主板驱动等... usb接口驱动异常怎么办,USB接口驱动异常是常见问题,通常由驱动损坏、系统更新冲突、硬件故障或电源管理设置导致。以下是常用解决

SpringBoot多数据源配置完整指南

《SpringBoot多数据源配置完整指南》在复杂的企业应用中,经常需要连接多个数据库,SpringBoot提供了灵活的多数据源配置方式,以下是详细的实现方案,需要的朋友可以参考下... 目录一、基础多数据源配置1. 添加依赖2. 配置多个数据源3. 配置数据源Bean二、JPA多数据源配置1. 配置主数据

SpringBoot中配置Redis连接池的完整指南

《SpringBoot中配置Redis连接池的完整指南》这篇文章主要为大家详细介绍了SpringBoot中配置Redis连接池的完整指南,文中的示例代码讲解详细,具有一定的借鉴价值,感兴趣的小伙伴可以... 目录一、添加依赖二、配置 Redis 连接池三、测试 Redis 操作四、完整示例代码(一)pom.

Java 正则表达式URL 匹配与源码全解析

《Java正则表达式URL匹配与源码全解析》在Web应用开发中,我们经常需要对URL进行格式验证,今天我们结合Java的Pattern和Matcher类,深入理解正则表达式在实际应用中... 目录1.正则表达式分解:2. 添加域名匹配 (2)3. 添加路径和查询参数匹配 (3) 4. 最终优化版本5.设计思