/**
|
* description 抖音打标签1 搜索关键词,随机浏览推荐页作品,命中关键词作品停留
|
* @搜索关键词, 命中关键词, 标题关键词
|
* @type {launch|{}}
|
*/
|
let launch = require("slib/launch"), actions = require("slib/actions"), dynamicData = require("slib/dynamicData"),
|
request = require("slib/request"), swiper = require("slib/swiper");
|
let ecSdk = require('slib/EASYCLICKSDK')
|
let scriptVersion = "2025.01.06"
|
logd("《chk百度打标签1》启动成功,版本:" + scriptVersion);
|
|
let storage = storages.create("storage"); //创建存储对象
|
storage.clear(); //清空存储
|
|
let platform = 4; //运行平台: 1抖音 2小红书 3快手 4百度 5QQ浏览器
|
let taskInfo = request.getTask(); //获取任务信息
|
if (taskInfo.tenantId) storage.putInt("tenantId", taskInfo.tenantId); //存储租户id
|
|
storage.putString("serial_num", time()); //存储任务流水号(生成时间戳)
|
|
let searchKeywords, hitKeywords; //搜索关键词, 命中关键词;
|
let label; //账号标签(同搜索内容)
|
let total = 3; //每次目标数
|
let gjcNum = 0;
|
let max_views = random(50, 60); //浏览作品数
|
let taskId = launch.taskThread(random(30, 40)); //开启任务时间线程 30分钟
|
let taskNums = random(10,15) // 町停时间 秒
|
let taskSwNum = random(3,5)
|
// taskInfo.valueJson = {
|
// 'baidu-hk标题关键词':'hk标题关键词',
|
// 'baidu-hk搜索关键词':'医美|植发|假体'
|
// }
|
if (taskInfo.valueJson) {
|
logd('获取任务数据:' + JSON.stringify(taskInfo.valueJson));
|
dynamicData.deviceLog(false, {log_detail: '获取任务数据:' + JSON.stringify(taskInfo.valueJson)});
|
//是否有任务参数
|
if (taskInfo.valueJson['baidu-hk标题关键词']) label = taskInfo.valueJson['baidu-hk标题关键词'].split("|");
|
logd('获取任务参数:标题关键词,' + JSON.stringify(label));
|
//是否有需求数据,没有则使用数组名称获取
|
if (taskInfo.valueJson['baidu-hk搜索关键词']) {
|
searchKeywords = taskInfo.valueJson['baidu-hk搜索关键词'].split("|");
|
logd('获取任务参数:搜索关键词,' + JSON.stringify(searchKeywords))
|
}
|
|
} else {
|
logd('没有任务参数');
|
dynamicData.deviceLog(false, {log_detail: '没有任务参数'});
|
}
|
let taskType = 2 //1 运行模式 2 无障碍模式
|
launch.launchDevice(taskId, taskType); //唤醒设备
|
|
main()
|
|
function main() {
|
// 1 关键词
|
// keyword
|
// 2 文章观看停留时长
|
// random()
|
// 3 浏览推荐时长
|
// time
|
// 4 换标签 时长
|
// time
|
// 5 总运行时长
|
// time
|
ecSdk.msg('程序执行')
|
let hasLaunchApp = launch.launchApp(4, 15000, 3); //打开百度APP
|
if (hasLaunchApp) {
|
launch.alertListener(4, taskId); //处理弹窗
|
}
|
//首页 处理逻辑
|
|
//&&isHome()
|
let gjNum = 0 //广告出现次数
|
while (!thread.isCancelled(taskId)) {
|
try {
|
//
|
logd('获取搜索框')
|
if (gjNum >= searchKeywords.length) {
|
gjNum = 0
|
}
|
let keyword = searchKeywords[gjNum];
|
let hasSearch = actions.searchByKeyword(keyword, 4); //通过schema打开openActivity界面,搜索关键词
|
if (hasSearch) {//需要判断是不是首页
|
logd('找到搜索框并点击成功,结果页找广告')
|
// result = true;
|
sleep(random(10, 30) * 100);
|
// actions.videoSwiper()
|
//
|
|
//结果页 需要翻页 多次查询
|
let nodeData = text("广告").pkg('com.baidu.searchbox').getOneNodeInfo(3 * 1000)
|
if (nodeData && nodeData != undefined) {
|
//找到需要点击广告 节点
|
let parentNode = nodeData.parent().parent()
|
if (parentNode && parentNode.click()) {
|
//等待
|
// randomSleep()
|
sleep(taskNums * 1000);
|
for (let i = 0; i < taskSwNum; i++) {
|
actions.videoSwiper()
|
sleep(1000);
|
}
|
// 返回到二级页面
|
isHome()
|
} else {
|
// 没有找到
|
//华东
|
actions.videoSwiper(null);
|
back()
|
}
|
} else {
|
logd('没有找到广告')
|
// actions.videoSwiper(null);
|
// actions.videoSwiper(null);
|
for (let i = 0; i < 3; i++) {
|
actions.videoSwiper()
|
randomSleep()
|
}
|
let tjNode = clz('android.widget.Button').getOneNodeInfo(3 * 1000) //text("大家还在搜").pkg('com.baidu.searchbox').getOneNodeInfo(3 * 1000)
|
if (tjNode && tjNode.click()) {
|
// let button = tjNode.parent().allChildren().clz('android.widget.Button').getOneNodeInfo('3000')
|
// if (button) {
|
// button.click()
|
// } else {
|
// toast('没有找到推荐 并点击')
|
for (let i = 0; i < 2; i++) {
|
actions.videoSwiper()
|
randomSleep()
|
}
|
isHome()
|
// }
|
} else {
|
toast('没有找到大家还在搜')
|
isHome()
|
}
|
//滑动
|
}
|
gjNum += 1
|
} else {
|
logd('不是首页去首页');
|
isHome()
|
}
|
} catch (e) {
|
loge('发生错误:' + e)
|
isHome()
|
randomSleep()
|
}
|
}
|
}
|
|
//
|
function checkGg() {
|
let flag = false
|
let nodeData = text("广告").pkg('com.baidu.searchbox').getOneNodeInfo(3 * 1000)
|
if (nodeData && nodeData != undefined) {
|
//找到需要点击广告 节点
|
let parentNode = nodeData.parent().parent()
|
if (parentNode && parentNode.click()) {
|
sleep(taskNums * 1000);
|
for (let i = 0; i < taskSwNum; i++) {
|
actions.videoSwiper()
|
sleep(1000);
|
}
|
flag = true
|
|
}
|
}
|
return flag
|
}
|
|
function isHome() {
|
let result = false;
|
while (true) {
|
var home_selectors = text("百度").getOneNodeInfo(3000); //首页按钮
|
// var message_selectors = text("消息").getOneNodeInfo(3000); //消息按钮
|
//判断是否在首页
|
if (home_selectors) {
|
var follow_selectors = text("好看视频"); //关注按钮
|
// var recommend_selectors = text("推荐"); //推荐按钮
|
if (has(follow_selectors)) {
|
toast('已定位首页');
|
// randomSleep("已定位到首页", "定位到首页", "", "", "", "");
|
result = true;
|
break;
|
} else {
|
home_selectors.click();
|
sleep(3000);
|
}
|
} else {
|
toast('返回首页...');
|
logd('返回首页...');
|
//返回上一页
|
actions.go_back(1);
|
}
|
}
|
return result;
|
}
|
|
function randomSleep() {
|
let min = Math.ceil(3);
|
let max = Math.floor(6);
|
let time = (Math.floor(Math.random() * (max - min + 1)) + min) * 1000;
|
sleep(time);
|
}
|
|
// 是否首页
|
|
|
// logd(searchKeywords);
|
// if (searchKeywords) {
|
|
// } else {
|
// logd('缺少关键词数据');
|
// actions.exceptionLog('缺少关键词数据');
|
// }
|
|
|
/**
|
* description 执行搜索
|
* @需要搜索多个关键词
|
* @return {boolean} : 返回是否成功
|
*/
|
function search() {
|
// let result = false;
|
|
// if (searchKeywords.length > 0) {
|
let keyword = searchKeywords[0];
|
// logd('准备执行搜索关键词:' + keyword);
|
dynamicData.deviceLog(false, {log_detail: '准备执行搜索关键词:' + keyword});
|
let hasSearch = actions.searchByKeyword(keyword, 4); //通过schema打开openActivity界面,搜索关键词
|
if (hasSearch) {
|
result = true;
|
}
|
// }
|
|
// return result;
|
|
// while (!thread.isCancelled(taskId)){
|
// ecSdk.初始化节点();
|
// //输入框
|
// // if(ecSdk.findNode("text","广告",24,true,true)) {
|
// // let searchLayout = id("com.baidu.searchbox:id/obfuscated").getOneNodeInfo(5000);
|
// // if(searchLayout){
|
//
|
// let searchBox = id('com.baidu.searchbox:id/baidu_searchbox').depth(15).getOneNodeInfo(5000)|| clz("android.widget.EditText").pkg("com.baidu.searchbox").getOneNodeInfo(5000)//;('com.baidu.searchbox:id/baidu_searchbox').
|
// let editableTextSelector = clz("android.widget.EditText").pkg("com.baidu.searchbox").depth(10).getOneNodeInfo(5000);
|
// // ecSdk.findNode("text","广告",24,true,true) ecSdk.找图('广告.png',true,)||
|
// if(ecSdk.findNode("text","广告",24,false,true)){
|
// ecSdk.findNode("text","广告",24,true,true)
|
// ecSdk.msg('广告找到并点击')
|
// sleep(4000);
|
// swipeToPoint(121, 1769, 121, 369, 1000);
|
// sleep(2000);
|
// for (let i = 0; i < 2; i++) {
|
// back();
|
// ecSdk.msg("返回", 1000);
|
// }
|
// }
|
// // else if(editableTextSelector){
|
// // editableTextSelector.pasteText('辣条')
|
// // ecSdk.msg('写入搜索值')
|
// // } else if(ecSdk.findNode("text","搜索",9,true,true)){
|
// // ecSdk.msg('搜索按钮找到并点击')
|
// // sleep(2000);
|
// // }
|
// else if(searchBox||editableTextSelector||ecSdk.findNode("text","搜索",9,false,true)){
|
// ecSdk.msg('搜索按钮')
|
// if(searchBox){
|
// searchBox.click()
|
// }
|
// if(editableTextSelector){
|
// let keyWords = searchKeywords[关键词执行位]
|
// if(关键词执行位<searchKeywords.length){
|
// 关键词执行位++
|
// }else {
|
// 关键词执行位 = 0
|
// }
|
// editableTextSelector.pasteText(keyWords)
|
// ecSdk.msg('写入搜索值')
|
// sleep(1000);
|
//
|
// }
|
// if(ecSdk.findNode("text","搜索",9,true,true)){
|
// ecSdk.msg('点击')
|
//
|
// }
|
// sleep(2000);
|
// // }else{
|
// //退出
|
// // exit()
|
// }
|
// // }else{
|
// // ecSdk.msg('没有找到搜索框')
|
// // }
|
//
|
// ecSdk.msg('程序执行中')
|
// }
|
}
|
|
|
/**
|
* description 浏览作品
|
* @ 商家作品
|
*/
|
function browseVideo1() {
|
let startNum = 0; //尝试抓取作品次数
|
let completedNumber = 0; //累计采集数
|
let reSearch = 0; //重新搜索次数
|
while (!thread.isCancelled(taskId)) {
|
logd('测试执行,app 操作 ');
|
if (completedNumber < total || completedNumber) {
|
try {
|
// begin common result page
|
sleep(random(1000, 4000));
|
//广告点击
|
let nodeData;
|
nodeData = clz("android.widget.TextView").text("广告").getOneNodeInfo(10 * 1000)
|
if (nodeData.click()) {
|
//begin ad detail
|
// nodeData.click()
|
// sleep(random(1000,3000))
|
// let i = 5; //swiper 5 times
|
// while(i>0){
|
sleep(random(1000, 5000))
|
let swipered = swiper.pageSwiper();
|
if (swipered) {
|
let nodeDat = clz("android.widget.TextView").text("广告").getOneNodeInfo(10 * 1000);
|
if (nodeDat.click()) {
|
sleep(random(1000, 3000))
|
}
|
}
|
// i--
|
// }
|
|
|
// sleep(random(1000,3000))
|
// 返回 首页
|
// let desc ;
|
// desc = desc("首页").getOneNodeInfo(5000)
|
// desc.click()
|
// end ad detail
|
} else {
|
throw 'err 跳出'
|
}
|
// end common result page
|
|
|
logd('查看信息');
|
|
completedNumber++;
|
} catch (e) {
|
// if (!thread.isCancelled(taskId)) {
|
//
|
// search();
|
//
|
// startNum++;
|
// }
|
search();
|
completedNumber++
|
}
|
} else {
|
searchKeywords.shift();
|
search();
|
}
|
|
}
|
}
|
|
function browseVideo() {//处理搜索之后逻辑
|
let startNum = 0;//尝试抓取作品次数
|
let completedNumber = 0;//累计采集数
|
let reSearch = 0;//重新搜索次数
|
while (!thread.isCancelled(taskId)) {
|
logd('测试百度搜索 标签');
|
sleep(random(1000, 4000))
|
let nodeData;
|
nodeData = text("广告").pkg('com.baidu.searchbox').getOneNodeInfo(3 * 1000) || clz('com.baidu.webkit.sdk.WebView').pkg('com.baidu.searchbox').getOneNodeInfo(3 * 1000);
|
if (nodeData && nodeData.click()) {
|
try {
|
sleep(random(1000, 4000));
|
let swipered = swiper.pageSwiper();
|
if (swipered) {
|
sleep(random(1000, 4000));
|
// 返回 首页
|
let desc;
|
// clz('android.widget.ImageView').
|
desc = desc("首页").getOneNodeInfo(5000)
|
// desc = id('com.baidu.searchbox:id/obfuscated').getOneNodeInfo(6000)
|
// com.baidu.searchbox:id/obfuscated
|
if (desc && desc.click()) {
|
sleep(random(1000, 3000));
|
//找下一个
|
if (reSearch > 1 && searchKeywords.length > 0) {
|
searchKeywords.shift();
|
search()
|
}
|
reSearch++
|
}
|
// end ad detail
|
}
|
} catch (e) {
|
//错误重新执行
|
if (!thread.isCancelled(taskId)) {
|
logd('未找到有效广告:' + e);
|
if (startNum < 3) {
|
logd('未找到广告信息,尝试翻页');
|
actions.videoSwiper(null);
|
} else {
|
logd('未找到广告信息,重新搜索');
|
//找下一个
|
if (reSearch > 1 && searchKeywords.length > 0) {
|
searchKeywords.shift();
|
search()
|
}
|
reSearch++
|
}
|
startNum++
|
}
|
}
|
} else {
|
if (startNum < 10) {
|
logd('未找到作品信息,尝试翻页');
|
actions.videoSwiper(null);
|
} else {
|
logd('未找到作品信息,重新搜索');
|
//找下一个
|
if (reSearch > 1 && searchKeywords.length > 0) {
|
searchKeywords.shift();
|
search()
|
}
|
reSearch++
|
}
|
startNum++
|
}
|
|
}
|
}
|