hk
yesterday eb0bd17432fbd71b11c6e55d78d79ed508350d27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
/**
 * 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++
        }
 
    }
}