autoJS pro-手机自动化脚本(douyin App模拟人工操作点赞、评论、收藏、转发)

            <div id="content_views" class="markdown_views prism-tomorrow-night">
                <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
                    <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
                </svg>
                <h2><a name="t0"></a><a id="autoJS_0"></a><a href="https://so.csdn.net/so/search?q=autoJS&amp;spm=1001.2101.3001.7020" target="_blank" class="hl hl-1" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.7020&quot;,&quot;dest&quot;:&quot;https://so.csdn.net/so/search?q=autoJS&amp;spm=1001.2101.3001.7020&quot;,&quot;extra&quot;:&quot;{\&quot;searchword\&quot;:\&quot;autoJS\&quot;}&quot;}" data-tit="autoJS" data-pretit="autojs">autoJS</a>自动化</h2> 

本人是一个web前端开发工程师,没想到可以用javascript来实现手机自动化,就有了之后的一系列文章,有好建议的同学欢迎评论区分享 ;-)

专栏地址:点击此处

在这里插入图片描述



开发环境

不同的环境可能导致部分代码运行有问题,所以开发者要确定好自己对应的环境

autojs版本:Pro 9.2.13-0
手机型号:小米8
android版本:10
开发工具:vscode
vscode连接插件:Auto.js-Pro-Ext
脚本对应软件douyin极速版 version22.3.0

链接

autojs参考文档:点击
CSDN专栏:点击
gitee地址:点击

背景

女朋友的douyin号每次更新总要叫我去帮他点赞、评论、收藏、转发,一次两次还好,后来懵了,就想着能不能做一个手机脚本,来解放双手。

这篇文章只用来实现点赞、评论、收藏、转发 等基础操作;
另外跳转到个人主页,跳转到指定视频页面的功能,自动下滑视频,随机执行基本操作,随机评论等…
咋们其他文章再写~~~

功能

1. 打开douyin极速版

// 根据APP名称打开APP
app.launchApp("抖音极速版");
//  设置脚本坐标点击所适合的屏幕宽高。如果脚本运行时,屏幕宽度不一致会自动放缩坐标。这个功能可以设置屏幕上坐标点击的等比缩放效果。
setScreenMetrics(1080, 1920);

 
 
  • 1
  • 2
  • 3
  • 4

2. 自定义函数实现点击功能

这边主要封装了一个函数,用于点击屏幕,主要原理是autojs Pro 的小机器人获取布局,根据布局调用合适的API,获取到组件的rect,并且点击其中心点位置,实现模拟点击功能

/**
 * @desc 根据条件点击找到组件,并且点击其中心点,并返回
 * @param {*} str 输入需要找到组件里面带的文本
 * @param {*} type 查找组件的类型,由此来确定需要调用什么方法
 * @param {*} index 索引
 * @param {*} offsetX 点击X轴偏移
 * @param {*} offsetY 点击X轴偏移
 * @returns 
 */
function clickByTextAndType(str, type, index, offsetX, offsetY) {
  if (!str) {
    throw ("请输入需要查找的组件文本");
  }

if (!type) {
throw (“请输入查找组件的类型”);
}

index = index ? index : 0;
offsetX = offsetX ? offsetX : 0;
offsetY = offsetY ? offsetY : 0;

var rect = null;
var collection = null;
switch (type) {
case “desc”: {
collection = descContains(str).find();
break;
}
case “text”: {
collection = textContains(str).find();
break;
}
default: {
throw (“请输入正确的查找组件的类型”);
return false;
}
}

// 判断有无找到组件
if (collection.empty()) {
throw (“没有找到该组件,” + str + “,” + type);
}

// 如果索引比长度小则拿最后一个
if (collection.length < (index + 1)) {
index = collection.length - 1;
}

// 找到了
rect = collection[index].bounds();

// 点击point
var point = {
x: rect.centerX() + offsetX,
y: rect.centerY() + offsetY
}
// 点击按钮
click(point.x, point.y);

return point;
}

  • 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

3. 基本操作

点赞、评论、收藏、转发只是控制点击跟输入input数据而已,这边就不细写,可以参考下面的源文件。


源文件

/*
 * @Author: Penk
 * @LastEditors: Penk
 * @LastEditTime: 2022-09-15 17:33:26
 * @FilePath: \autojs-demo\douyin基本操作.js
 */
// 根据APP名称打开APP
app.launchApp("抖音极速版");
//  设置脚本坐标点击所适合的屏幕宽高。如果脚本运行时,屏幕宽度不一致会自动放缩坐标。这个功能可以设置屏幕上坐标点击的等比缩放效果。
setScreenMetrics(1080, 1920);
sleep(5000);

var mApp = { }

/**

  • @desc 根据条件点击找到组件,并且点击其中心点,并返回
  • @param {*} str 输入需要找到组件里面带的文本
  • @param {*} type 查找组件的类型,由此来确定需要调用什么方法
  • @param {*} index 索引
  • @param {*} offsetX 点击X轴偏移
  • @param {*} offsetY 点击X轴偏移
  • @returns
    */
    function clickByTextAndType(str, type, index, offsetX, offsetY) {
    if (!str) {
    throw (“请输入需要查找的组件文本”);
    }

if (!type) {
throw (“请输入查找组件的类型”);
}

index = index ? index : 0;
offsetX = offsetX ? offsetX : 0;
offsetY = offsetY ? offsetY : 0;

var rect = null;
var collection = null;
switch (type) {
case “desc”: {
collection = descContains(str).find();
break;
}
case “text”: {
collection = textContains(str).find();
break;
}
default: {
throw (“请输入正确的查找组件的类型”);
return false;
}
}

// 判断有无找到组件
if (collection.empty()) {
throw (“没有找到该组件,” + str + “,” + type);
}

// 如果索引比长度小则拿最后一个
if (collection.length < (index + 1)) {
index = collection.length - 1;
}

// 找到了
rect = collection[index].bounds();

// 点击point
var point = {
x: rect.centerX() + offsetX,
y: rect.centerY() + offsetY
}
// 点击按钮
click(point.x, point.y);

return point;
}

// douyin操作-点赞
mApp.zan = function () {
clickByTextAndType(“未点赞”, “desc”);
}

// douyin操作-评论
mApp.comment = function () {
// 点击评论按钮
clickByTextAndType(“评论”, “desc”);

sleep(random(500, 1000));
// 输入评论
setText(0,“素质3连,马上安排上…”);

sleep(random(1000, 5000));
// 点击发送
clickByTextAndType(“发送”, “desc”);

sleep(random(1000, 5000));
// 点击空白处
back();
}

// douyin操作-收藏
mApp.collect = function () {
// 点击收藏按钮
clickByTextAndType(“未选中,收藏”, “desc”);
}

// douyin操作-转发
mApp.transmit = function () {
// 点击转发按钮
clickByTextAndType(“分享”, “desc”);

sleep(random(1000, 2000));
// 私信朋友按钮
clickByTextAndType(“私信”, “text”);

sleep(random(1000, 2000));
// 私信朋友按钮
var point = clickByTextAndType(“分享”, “desc”, random(0, 2));

sleep(random(1000, 2000));
// 继续点击该位置,可以发信息
click(point.x, point.y);

sleep(random(1000, 2000));
// 输入信息
setText(0,“素质3连,马上安排上…”);

sleep(random(1000, 2000));
// 点击发送
clickByTextAndType(“发送”, “desc”);
}

// 直接调用
mApp.transmit();

  • 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值