| | |
| | | // 关键词搜索视频 对命中评论随机进行回复, 私信, 点赞操作 |
| | | |
| | | let launch = require("slib/launch"), actions = require("slib/actions"), dynamicData = require("slib/dynamicData"), |
| | | swiper = require("slib/swiper"), datas = require("slib/datas"), request = require("slib/request"), date = require("slib/date"); |
| | | swiper = require("slib/swiper"), datas = require("slib/datas"), request = require("slib/request"), |
| | | date = require("slib/date"); |
| | | |
| | | let storage = storages.create("storage"); //创建存储对象 |
| | | storage.clear(); //清空存储 |
| | |
| | | |
| | | //操作类型 |
| | | let actionType = [{ |
| | | type : 1, |
| | | name : '评论回复', |
| | | p : 10 |
| | | type: 1, |
| | | name: '评论回复', |
| | | p: 10 |
| | | }, { |
| | | type : 2, |
| | | name : '评论用户私信', |
| | | p : 5 |
| | | type: 2, |
| | | name: '评论用户私信', |
| | | p: 5 |
| | | }, { |
| | | type : 3, |
| | | name : '评论点赞', |
| | | p : 30 |
| | | type: 3, |
| | | name: '评论点赞', |
| | | p: 30 |
| | | }]; |
| | | |
| | | //测试数据 |
| | |
| | | |
| | | if (taskInfo.valueJson) { |
| | | logd('获取任务数据:' + JSON.stringify(taskInfo.valueJson)); |
| | | dynamicData.deviceLog(false, { log_detail : '获取任务数据:' + JSON.stringify(taskInfo.valueJson) }); |
| | | dynamicData.deviceLog(false, {log_detail: '获取任务数据:' + JSON.stringify(taskInfo.valueJson)}); |
| | | if (taskInfo.valueJson['平台']) { |
| | | let object = datas.platforms.find(function (item,index) { |
| | | let object = datas.platforms.find(function (item, index) { |
| | | return item.name === taskInfo.valueJson['平台']; |
| | | }); |
| | | platform = object.value; |
| | |
| | | /** |
| | | * description 浏览作品 |
| | | */ |
| | | function browseVideo () { |
| | | function browseVideo() { |
| | | let startNum = 0; //尝试抓取作品次数 |
| | | while (!thread.isCancelled(taskId)) { |
| | | let videoInfo = actions.getVideoInfo(platform); //作品页信息 |
| | | //是否为有效作品 |
| | | if (videoInfo) { |
| | | startNum = 0; |
| | | try{ |
| | | try { |
| | | //是否有评论 |
| | | if (videoInfo.commentCountSelector.text === "评论" || videoInfo.commentCountSelector.text === 0) { |
| | | dynamicData.deviceLog(false, { log_detail: '该作品无评论,略过' }); |
| | | dynamicData.deviceLog(false, {log_detail: '该作品无评论,略过'}); |
| | | swiper.pageSwiper(); |
| | | continue; |
| | | } |
| | |
| | | if (platform === 1) business_user = desc("查看详情").getOneNodeInfo(5000); |
| | | if (platform === 3) business_user = id("com.smile.gifmaker:id/slide_play_right_link_icon").getOneNodeInfo(5000); |
| | | if (business_user) { |
| | | dynamicData.deviceLog(false, { log_detail: '发现广告,略过' }); |
| | | dynamicData.deviceLog(false, {log_detail: '发现广告,略过'}); |
| | | swiper.pageSwiper(); |
| | | continue; |
| | | } |
| | |
| | | let log = { //日志参数组 |
| | | log_detail: '正在浏览作品', |
| | | operate_type: 5, |
| | | post_name : videoInfo.postSelector.text, |
| | | post_user_nickname : videoInfo.nameSelector.text, |
| | | post_user_no : author.id, |
| | | uid : uid |
| | | post_name: videoInfo.postSelector.text, |
| | | post_user_nickname: videoInfo.nameSelector.text, |
| | | post_user_no: author.id, |
| | | uid: uid |
| | | }; |
| | | dynamicData.deviceLog(true, log); //日志 |
| | | dynamicData.insertTrace(log); //埋点 |
| | |
| | | log.log_detail = '获取视频地址失败'; |
| | | dynamicData.deviceLog(true, log); |
| | | } |
| | | clickPoint(device.getScreenWidth()/2, device.getScreenHeight()/2); //点击屏幕中心 |
| | | clickPoint(device.getScreenWidth() / 2, device.getScreenHeight() / 2); //点击屏幕中心 |
| | | sleep(4000); |
| | | |
| | | //进入评论 |
| | |
| | | if (!thread.isCancelled(taskId)) { |
| | | let error = { |
| | | log_detail: '未找到有效作品:' + e, |
| | | operate_type : 16 |
| | | operate_type: 16 |
| | | } |
| | | dynamicData.deviceLog(false, error); |
| | | dynamicData.insertTrace(error); |
| | | if (startNum < 2 || startNum === 3) { |
| | | swiper.pageSwiper(); |
| | | dynamicData.deviceLog(false, { log_detail: '未找到作品信息,尝试翻页' }); |
| | | } else if (startNum === 2 || startNum === 4 || startNum === 5) { |
| | | dynamicData.deviceLog(false, {log_detail: '未找到作品信息,尝试翻页'}); |
| | | } else if (startNum === 2 || startNum === 4 || startNum === 5) { |
| | | actions.go_back(1); |
| | | dynamicData.deviceLog(false, { log_detail: '未找到作品信息,尝试返回' }); |
| | | dynamicData.deviceLog(false, {log_detail: '未找到作品信息,尝试返回'}); |
| | | } else { |
| | | search(); |
| | | dynamicData.deviceLog(false, { log_detail: '未找到作品信息,重新搜索' }); |
| | | dynamicData.deviceLog(false, {log_detail: '未找到作品信息,重新搜索'}); |
| | | } |
| | | startNum++; |
| | | } |
| | |
| | | } else { |
| | | if (startNum < 2 || startNum === 3) { |
| | | swiper.pageSwiper(); |
| | | dynamicData.deviceLog(false, { log_detail: '未找到作品信息,尝试翻页' }); |
| | | } else if (startNum === 2 || startNum === 4 || startNum === 5) { |
| | | dynamicData.deviceLog(false, {log_detail: '未找到作品信息,尝试翻页'}); |
| | | } else if (startNum === 2 || startNum === 4 || startNum === 5) { |
| | | actions.go_back(1); |
| | | dynamicData.deviceLog(false, { log_detail: '未找到作品信息,尝试返回' }); |
| | | dynamicData.deviceLog(false, {log_detail: '未找到作品信息,尝试返回'}); |
| | | } else { |
| | | search(); |
| | | dynamicData.deviceLog(false, { log_detail: '未找到作品信息,重新搜索' }); |
| | | dynamicData.deviceLog(false, {log_detail: '未找到作品信息,重新搜索'}); |
| | | } |
| | | startNum++; |
| | | } |
| | |
| | | * description 浏览评论 |
| | | * @param log {object} : 日志参数组 |
| | | */ |
| | | function browseComments (log) { |
| | | function browseComments(log) { |
| | | let c_log = log; |
| | | let startNum = 0; //尝试抓取评论次数 |
| | | let num = 0, swiperTimes = 0, content; //当前作品命中数量,已翻页次数,评论内容 |
| | | browse : |
| | | while (!thread.isCancelled(taskId)) { |
| | | if (platform === 1) content = id("com.ss.android.ugc.aweme:id/content").drawingOrder(27).getNodeInfo(10000); |
| | | if (platform === 2) content = depth(17).getNodeInfo(10000); |
| | | if (platform === 3) content = id("com.smile.gifmaker:id/comment").getNodeInfo(10000); |
| | | //是否有评论 |
| | | if (content) { |
| | | startNum = 0; |
| | | for (let i = 0; i < content.length; i++) { |
| | | try { |
| | | //是否完成总命中量 |
| | | if (completedNumber === total) { |
| | | dynamicData.deviceLog(false, { log_detail: '任务完成,准备关闭脚本', operate_type: 2 }); |
| | | exit(); |
| | | break browse; |
| | | } else if (num === everyNumber) { |
| | | dynamicData.deviceLog(true, { log_detail: '当前视频互动完成' }); |
| | | break browse; |
| | | } else { |
| | | let comments = content[i].text; //评论内容 |
| | | if (comments) { |
| | | for (let n = 0; n < hitKeywords.length; n++) { |
| | | //是否命中 |
| | | if (comments.includes(hitKeywords[n])) { |
| | | //是否为作者评论 |
| | | let author; |
| | | if (platform === 1) author = content[i].parent().getOneNodeInfo(text("作者"), 2000); |
| | | if (platform === 3) author = content[i].parent().parent().getOneNodeInfo(id("com.smile.gifmaker:id/comment_author_tag"), 2000); |
| | | if (author) { |
| | | dynamicData.deviceLog(false, { log_detail : '发现作者评论,略过' }); |
| | | break; |
| | | } |
| | | while (!thread.isCancelled(taskId)) { |
| | | if (platform === 1) content = id("com.ss.android.ugc.aweme:id/content").drawingOrder(27).getNodeInfo(10000); |
| | | if (platform === 2) content = depth(17).getNodeInfo(10000); |
| | | if (platform === 3) content = id("com.smile.gifmaker:id/comment").getNodeInfo(10000); |
| | | //是否有评论 |
| | | if (content) { |
| | | startNum = 0; |
| | | for (let i = 0; i < content.length; i++) { |
| | | try { |
| | | //是否完成总命中量 |
| | | if (completedNumber === total) { |
| | | dynamicData.deviceLog(false, {log_detail: '任务完成,准备关闭脚本', operate_type: 2}); |
| | | exit(); |
| | | break browse; |
| | | } else if (num === everyNumber) { |
| | | dynamicData.deviceLog(true, {log_detail: '当前视频互动完成'}); |
| | | break browse; |
| | | } else { |
| | | let comments = content[i].text; //评论内容 |
| | | if (comments) { |
| | | for (let n = 0; n < hitKeywords.length; n++) { |
| | | //是否命中 |
| | | if (comments.includes(hitKeywords[n])) { |
| | | //是否为作者评论 |
| | | let author; |
| | | if (platform === 1) author = content[i].parent().getOneNodeInfo(text("作者"), 2000); |
| | | if (platform === 3) author = content[i].parent().parent().getOneNodeInfo(id("com.smile.gifmaker:id/comment_author_tag"), 2000); |
| | | if (author) { |
| | | dynamicData.deviceLog(false, {log_detail: '发现作者评论,略过'}); |
| | | break; |
| | | } |
| | | |
| | | c_log.keyword = hitKeywords[n]; |
| | | c_log.comment = comments; |
| | | c_log.operate_type = 17; |
| | | c_log.log_detail = '该作品第' + (swiperTimes + 1) + '页第' + (i + 1) + '条评论命中关键词:' + hitKeywords[n]; |
| | | dynamicData.deviceLog(true, c_log); |
| | | dynamicData.insertTrace(c_log); |
| | | delete c_log.operate_type; |
| | | c_log.keyword = hitKeywords[n]; |
| | | c_log.comment = comments; |
| | | c_log.operate_type = 17; |
| | | c_log.log_detail = '该作品第' + (swiperTimes + 1) + '页第' + (i + 1) + '条评论命中关键词:' + hitKeywords[n]; |
| | | dynamicData.deviceLog(true, c_log); |
| | | dynamicData.insertTrace(c_log); |
| | | delete c_log.operate_type; |
| | | |
| | | //获取评论日期 |
| | | let dateSelector; |
| | | if (platform === 1) dateSelector = content[i].nextSiblings()[0].child(0); |
| | | if (dateSelector) { |
| | | let commentDate = date.getCommentDate(dateSelector.text); |
| | | if (commentDate) c_log.comment_datetime = commentDate; |
| | | } |
| | | //获取评论日期 |
| | | let dateSelector; |
| | | if (platform === 1) dateSelector = content[i].nextSiblings()[0].child(0); |
| | | if (dateSelector) { |
| | | let commentDate = date.getCommentDate(dateSelector.text); |
| | | if (commentDate) c_log.comment_datetime = commentDate; |
| | | } |
| | | |
| | | |
| | | //获取用户账号信息 |
| | | let avatar, user; //头像节点 用户信息 |
| | | if (platform === 1) avatar = content[i].previousSiblings()[1] ? content[i].previousSiblings()[1] : ''; |
| | | if (platform === 2) avatar = content[i].parent().previousSiblings()[0] ? content[i].parent().previousSiblings()[0] : ''; |
| | | if (platform === 3) avatar = content[i].parent().parent().previousSiblings()[2] ? content[i].parent().parent().previousSiblings()[2] : ''; |
| | | //获取用户账号信息 |
| | | let avatar, user; //头像节点 用户信息 |
| | | if (platform === 1) avatar = content[i].previousSiblings()[1] ? content[i].previousSiblings()[1] : ''; |
| | | if (platform === 2) avatar = content[i].parent().previousSiblings()[0] ? content[i].parent().previousSiblings()[0] : ''; |
| | | if (platform === 3) avatar = content[i].parent().parent().previousSiblings()[2] ? content[i].parent().parent().previousSiblings()[2] : ''; |
| | | |
| | | if (avatar) { |
| | | user = actions.getUserInfo(avatar, platform); //获取用户信息 |
| | | actions.go_back(1); |
| | | } |
| | | if (avatar) { |
| | | user = actions.getUserInfo(avatar, platform); //获取用户信息 |
| | | actions.go_back(1); |
| | | } |
| | | |
| | | if (user.id !=='' && user.nickname !=='') { |
| | | if (user.id !== '' && user.nickname !== '') { |
| | | num++; |
| | | completedNumber++; |
| | | c_log.comment_user_no = user.id; |
| | | c_log.comment_user_nickname = user.nickname; |
| | | dynamicData.comments_got(c_log); //抓取命中评论 |
| | | dynamicData.deviceLog(true, {log_detail: '已采集' + completedNumber + '个命中评论'}); |
| | | } |
| | | |
| | | let action = actionRandom(); |
| | | log.log_detail = '准备对该评论进行:' + action.name; |
| | | dynamicData.deviceLog(true, c_log); |
| | | if (action.type === 1) actions.commentReply(content[i], log); //评论回复 |
| | | if (action.type === 2) { |
| | | if (messageNumber > 99) { |
| | | log.log_detail = '私信次数已达上限,取消操作'; |
| | | dynamicData.deviceLog(true, log); |
| | | } else { |
| | | actions.message(avatar, platform, log); //私信 |
| | | messageNumber++; |
| | | } |
| | | } |
| | | if (action.type === 3) { |
| | | let loving; //点赞爱心节点 |
| | | if (platform === 1) loving = content[i].nextSiblings()[1].child(0); |
| | | if (platform === 2) loving = content[i].parent().nextSiblings()[0]; |
| | | if (platform === 3) loving = content[i].parent().parent().nextSiblings()[1].child(0); |
| | | actions.like(loving, log); //点赞 |
| | | } |
| | | |
| | | num++; |
| | | completedNumber++; |
| | | c_log.comment_user_no = user.id; |
| | | c_log.comment_user_nickname = user.nickname; |
| | | dynamicData.comments_got(c_log); //抓取命中评论 |
| | | dynamicData.deviceLog(true, { log_detail : '已采集' + completedNumber + '个命中评论' }); |
| | | dynamicData.deviceLog(false, {log_detail: '已处理第' + completedNumber + '个命中评论'}); |
| | | break; |
| | | } |
| | | |
| | | let action = actionRandom(); |
| | | log.log_detail = '准备对该评论进行:' + action.name; |
| | | dynamicData.deviceLog(true, c_log); |
| | | if (action.type === 1) actions.commentReply(content[i], log); //评论回复 |
| | | if (action.type === 2) { |
| | | if (messageNumber > 99) { |
| | | log.log_detail = '私信次数已达上限,取消操作'; |
| | | dynamicData.deviceLog(true, log); |
| | | } else { |
| | | actions.message(avatar, platform, log); //私信 |
| | | messageNumber++; |
| | | } |
| | | } |
| | | if (action.type === 3) { |
| | | let loving; //点赞爱心节点 |
| | | if (platform === 1) loving = content[i].nextSiblings()[1].child(0); |
| | | if (platform === 2) loving = content[i].parent().nextSiblings()[0]; |
| | | if (platform === 3) loving = content[i].parent().parent().nextSiblings()[1].child(0); |
| | | actions.like(loving, log); //点赞 |
| | | } |
| | | |
| | | num++; |
| | | completedNumber++; |
| | | dynamicData.deviceLog(false, {log_detail: '已处理第' + completedNumber + '个命中评论'}); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (e) { |
| | | if (!thread.isCancelled(taskId)) { |
| | | if (startNum < 2) { |
| | | dynamicData.deviceLog(true, { log_detail: '尝试重新查找评论' }); |
| | | break; |
| | | } else { |
| | | break browse; |
| | | } catch (e) { |
| | | if (!thread.isCancelled(taskId)) { |
| | | if (startNum < 2) { |
| | | dynamicData.deviceLog(true, {log_detail: '尝试重新查找评论'}); |
| | | break; |
| | | } else { |
| | | break browse; |
| | | } |
| | | startNum++; |
| | | } |
| | | startNum++; |
| | | } |
| | | } |
| | | } |
| | | let notPage; |
| | | if (platform === 1) notPage = textMatch(".*暂时没有更多.*").getOneNodeInfo(5000); |
| | | if (platform === 3) notPage = id("com.smile.gifmaker.comment_detail:id/no_more_content").getOneNodeInfo(5000); |
| | | let login = text("登录看更多精彩评论").getOneNodeInfo(5000); |
| | | if (notPage || login || swiperTimes > max_swiperTimes) { |
| | | dynamicData.deviceLog(true, { log_detail: '已浏览全部评论' }); |
| | | break browse; |
| | | let notPage; |
| | | if (platform === 1) notPage = textMatch(".*暂时没有更多.*").getOneNodeInfo(5000); |
| | | if (platform === 3) notPage = id("com.smile.gifmaker.comment_detail:id/no_more_content").getOneNodeInfo(5000); |
| | | let login = text("登录看更多精彩评论").getOneNodeInfo(5000); |
| | | if (notPage || login || swiperTimes > max_swiperTimes) { |
| | | dynamicData.deviceLog(true, {log_detail: '已浏览全部评论'}); |
| | | break browse; |
| | | } else { |
| | | log.log_detail = '第' + (swiperTimes + 1) + '次评论翻页'; |
| | | log.operate_type = 18; |
| | | swiper.pageSwiper(); |
| | | dynamicData.deviceLog(false, log); |
| | | dynamicData.insertTrace(log); |
| | | delete log.operate_type; |
| | | swiperTimes++; |
| | | } |
| | | } else { |
| | | log.log_detail = '第' + (swiperTimes + 1) + '次评论翻页'; |
| | | log.operate_type = 18; |
| | | swiper.pageSwiper(); |
| | | dynamicData.deviceLog(false, log); |
| | | dynamicData.insertTrace(log); |
| | | delete log.operate_type; |
| | | swiperTimes++; |
| | | dynamicData.deviceLog(true, {log_detail: '未找到评论'}); |
| | | break; |
| | | } |
| | | } else { |
| | | dynamicData.deviceLog(true, { log_detail: '未找到评论' }); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * description 获取云控参数 |
| | | * @return {boolean} : 返回是否成功 |
| | | */ |
| | | function getECloudData () { |
| | | function getECloudData() { |
| | | let result = false, data, hasData = true, value; |
| | | //通过数据组名或数据名称取得数据 |
| | | let group = [{ |
| | | "groupName" : "短视频代运营话术", |
| | | "dataName" : "斗因-回复评论话术" |
| | | },{ |
| | | "groupName" : "短视频代运营话术", |
| | | "dataName" : "斗因-私信话术" |
| | | "groupName": "短视频代运营话术", |
| | | "dataName": "斗因-回复评论话术" |
| | | }, { |
| | | "groupName": "短视频代运营话术", |
| | | "dataName": "斗因-私信话术" |
| | | }]; |
| | | for (let i = 0; i < group.length; i++) { |
| | | data = ecloud.getData(group[i]); |
| | |
| | | } |
| | | if (!value || value.length == 0) { |
| | | hasData = false; |
| | | dynamicData.deviceLog(false, { log_detail : '未设置' + group[i].dataName }); |
| | | dynamicData.deviceLog(false, {log_detail: '未设置' + group[i].dataName}); |
| | | break; |
| | | } |
| | | } else { |
| | | hasData = false; |
| | | dynamicData.deviceLog(false, { log_detail : '未获取' + group[i].dataName }); |
| | | dynamicData.deviceLog(false, {log_detail: '未获取' + group[i].dataName}); |
| | | break; |
| | | } |
| | | } |
| | | if (hasData) { |
| | | dynamicData.deviceLog(true, { log_detail : '已获取任务数据,准备启动应用' }); |
| | | dynamicData.deviceLog(true, {log_detail: '已获取任务数据,准备启动应用'}); |
| | | result = true; |
| | | } |
| | | return result; |
| | |
| | | /** |
| | | * description 随机选取操作 |
| | | */ |
| | | function actionRandom () { |
| | | function actionRandom() { |
| | | let sum = 0; |
| | | for (let i = 0;i < actionType.length; i++) { |
| | | for (let i = 0; i < actionType.length; i++) { |
| | | sum += actionType[i].p; |
| | | } |
| | | let randomNumber = Math.random() * sum; |
| | | for (let n = 0;n < actionType.length; n++) { |
| | | for (let n = 0; n < actionType.length; n++) { |
| | | randomNumber -= actionType[n].p; |
| | | if (randomNumber <= 0) { |
| | | return actionType[n]; |
| | |
| | | * description 执行搜索 |
| | | * @return {boolean} : 返回是否成功 |
| | | */ |
| | | function search () { |
| | | function search() { |
| | | let result = false; |
| | | let hasSearch = actions.searchVideoByKeyword(searchContent, platform); //根据关键词搜索视频 |
| | | if (hasSearch) { |