python脚本实现自动钉钉打卡的技术实现细节

pip使用国内镜像源

[ 个人推荐清华大学pypi镜像站(https://mirrors.tuna.tsinghua.edu.cn/help/pypi/),每五分钟同步一次,资源丰富,下载速度很快 ] : 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple 中国科学技术大学 : https://pypi.mirrors.ustc.edu.cn/simple 阿里云:http://mirrors.aliyun.com/pypi/simple/ 豆瓣:http://pypi.douban.com/simple/

临时使用

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy

#如果上一个提示不受信任,就使用这个,此参数“--trusted-host”表示信任
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple--trusted-host pypi.tuna.tsinghua.edu.cn

永久使用国内镜像源进行 pip安装

1.Windows平台安装方式 进入相应目录下 C盘->Users/用户->xxx->新建pip文件夹->新建pip.ini文件

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

安卓调试工具集合

adb工具Android Platform Tools

https://developer.android.google.cn/studio/releases/platform-tools

安装完成,电脑USB连接手机,cmd如下命令,可以看到连接是设备列表

adb devices
adb server version (32) doesnt match this client (41); killing...
* daemon started successfully
List of devices attached
TPG5T182060sssss        device

uiautomator2

谷歌公司进行UI自动化测试工具uiautomator的Python版本,功能类似浏览器F12中可以根据ID找到UI元素的位置,并做出相应的手势动作模拟人为操作

pip install --pre -U uiautomator2 #默认安装最新版本

设备安装atx-agent 首先设备连接到PC,并能够adb devices发现该设备(参考adb工具安装步骤)。

$ python -m uiautomator2 init
success

命令会从github下载atx-agent文件,并推送到手机。在手机上安装包名为com.github.uiautomator的apk

看到success ,代表atx-agent初始化成功。手机上会出现一个小汽车图标的应用。 安装一个名称为ATX的apk,打开后点击“启动”

控件定位工具

安装控件定位工具,帮助我们获取屏幕中的控件(推荐)

weditor beta 针对Android和iOS原生应用快速定位元素坐标,自动生成代码并点击运行。 安装方式:

pip install --pre weditor
 python -m weditor
listening on http://192.168.1.5:17310

打开web页面,你会发现豌豆荚等其他手机管理软件可以电脑点击界面的原理就来自于此而已 http://localhost:17310

UiAutomatorViewer JAR获取屏幕中的控件(建议放弃使用,太麻烦)

UiAutomatorViewer 是安卓SDK中自带的工具,而且下载SDK太占空间,也不太好用

Android-SDK 3.0.0(UiAutomatorViewer 启动依赖) 链接:https://pan.baidu.com/s/1htr6wOO 密码:8lp9

UiAutomatorViewer JAR(帮助我们获取屏幕中的控件,并使用脚本操作) 链接:https://pan.baidu.com/s/1i6X1MAx 密码:kfco

ADB连接手机或者模拟器 打开 Android-SDK 目录下的 uiautomatorviewer.bat 进行编辑 将bindir= 后面的字符串修改成 上文 安装的ADB工具的安装目录(不修改将会造成闪退)

bindir=c:progranmadb

输入adb devices 双击打开 Android-SDK 目录下的 uiautomatorviewer.bat !点击第二个按钮! 选择端口选项 点击OK!出现下图, 到此uiautomatorviewer工具的使用介绍 连接手机界面后,右边就是APP的各种包名和控件ID,我们可以从这里得到真实APP的控件id后在脚本中进行我们自己想要的操作效果。

python -m atx gui

钉钉脚本缩减版

uiautomator2 使用WIFI模式链接到局域网手机后执行如下脚本,整个流程是这样的,具体细节需要优化的地方后面有时间在说

about me

经验分享 程序员 微信小程序 职场和发展