>
uiautomator
>
app小程序手机端Python爬虫实战03-uiautomater2项目初始化
uiautomator
虚幻
安装
uiautomator2
pip install uiautomator2 -i https://pypi.douban.com/simple/
安装完成后,可以看到安装了这么多库
三、对移动设备执行初始化
首先确保手机设备成功接通:
接下来进行最重要的操作,对移动设备初始化。
这个过程会在移动设备上,安装一个agent
python -m uiautomator2 init
如果你的电脑上有其他的python,你想要安装到指定的python下,可以这样修改上面的命令
C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe -m uiautomator2 init
ModuleNotFoundError: No module named 'dataclasses'
就安装这个库
pip install dataclasses
再次运行就可以看到安装成功了:
C:\Users\Administrator\Desktop\u2_project>C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe -m uiautomator2 init
[I 220730 16:18:46 init:156] uiautomator2 version: 2.16.18
[I 220730 16:18:46 init:373] Install minicap, minitouch
[D 220730 16:18:46 init:62] Download https://tool.appetizer.io/openatx/stf-binaries/raw/0.3.0/node_modules/@devicefarmer/minitouch-prebuilt/prebuilt/x86/bin/minitouch
minitouch |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 33.6 KB/33.6 KB
?[?25h[D 220730 16:18:46 init:238] Push to /data/local/tmp/minitouch:0755
[I 220730 16:18:46 init:377] abi:x86 not supported well, skip install minicap
[D 220730 16:18:46 init:256] apk-debug package-info: None
[D 220730 16:18:46 init:257] apk-debug-test package-info: None
[I 220730 16:18:46 init:388] Install com.github.uiautomator, com.github.uiautomator.test 2.3.3
[D 220730 16:18:46 init:167] Shell: ('pm', 'uninstall', 'com.github.uiautomator')
[D 220730 16:18:47 init:167] Shell: ('pm', 'uninstall', 'com.github.uiautomator.test')
[D 220730 16:18:47 init:62] Download https://tool.appetizer.io/openatx/android-uiautomator-server/releases/download/2.3.3/app-uiautomator.apk
app-uiautomator.apk |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 2.1 MB/2.1 MB
?[?25h[D 220730 16:18:48 init:238] Push to /data/local/tmp/app-uiautomator.apk:0644
[D 220730 16:18:48 init:167] Shell: ('pm', 'install', '-r', '-t', '/data/local/tmp/app-uiautomator.apk')
[I 220730 16:18:49 init:331] - app-uiautomator.apk installed
[D 220730 16:18:49 init:62] Download https://tool.appetizer.io/openatx/android-uiautomator-server/releases/download/2.3.3/app-uiautomator-test.apk
app-uiautomator-test.apk |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 1.0 MB/1.0 MB
?[?25h[D 220730 16:18:49 init:238] Push to /data/local/tmp/app-uiautomator-test.apk:0644
[D 220730 16:18:49 init:167] Shell: ('pm', 'install', '-r', '-t', '/data/local/tmp/app-uiautomator-test.apk')
[I 220730 16:18:50 init:331] - app-uiautomator-test.apk installed
[D 220730 16:18:50 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--stop')
[I 220730 16:18:50 init:346] Install atx-agent 0.10.0
[D 220730 16:18:50 init:62] Download https://tool.appetizer.io/openatx/atx-agent/releases/download/0.10.0/atx-agent_0.10.0_linux_386.tar.gz
atx-agent_0.10.0_linux_386.tar.gz |⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿| 4.2 MB/4.2 MB
?[?25h[D 220730 16:18:51 init:238] Push to /data/local/tmp/atx-agent:0755
[D 220730 16:18:53 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d', '--addr', '127.0.0.1:7912')
[I 220730 16:18:53 init:350] Check atx-agent version
[D 220730 16:18:53 init:359] Forward: local:tcp:52537 -> remote:tcp:7912
[D 220730 16:18:54 init:359] Forward: local:tcp:52537 -> remote:tcp:7912
[D 220730 16:18:54 init:362] atx-agent version 0.10.0
[D 220730 16:18:54 init:366] device wlan ip: 172.17.99.15
Successfully init AdbDevice(serial=127.0.0.1:62001)
并且,在你的手机上,也会有一个ATX
所以刚才我们输入的uiautomator init
命令会执行哪些操作呢 ?
他会安装3个包,
- uiautomator-server:谷歌原生的uiautomator
- atx-agent:uiautomator的守护进程
- atx-agent增加远程控制的功能,依赖minicap和minitouch这两个工具
初始化完成后,既可以在这个目录下看到这几个包了:
C:\Users\Administrator\.uiautomator2\cache
四、通过wifi方式连接手机
import uiautomator2 as u2
# 通过手机的序列号接通
d = u2.connect_usb("127.0.0.1:62001")
print(d.info)
可以看到设备的数据被正常打印出来
C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe C:/Users/Administrator/Desktop/u2_project/testu2.py
[W 220730 16:56:46 __init__:218] [pid:15028] atx-agent has something wrong, auto recovering
[D 220730 16:56:46 __init__:317] [pid:15028] [127.0.0.1:62001] device 127.0.0.1:62001 is online
[I 220730 16:56:46 init:156] uiautomator2 version: 2.16.18
[D 220730 16:56:46 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--stop')
[D 220730 16:56:46 init:296] Real version: [0, 10, 0], Expect version: [0, 10, 0]
[D 220730 16:56:46 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d', '--addr', '127.0.0.1:7912')
[I 220730 16:56:46 init:350] Check atx-agent version
[D 220730 16:56:46 init:359] Forward: local:tcp:54071 -> remote:tcp:7912
[D 220730 16:56:46 init:359] Forward: local:tcp:54071 -> remote:tcp:7912
[D 220730 16:56:47 init:362] atx-agent version 0.10.0
[D 220730 16:56:47 init:366] device wlan ip: 172.17.99.15
[D 220730 16:56:47 __init__:656] [pid:15028] [127.0.0.1:62001] kill process(ps): uiautomator
[D 220730 16:56:48 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 40.0s
[D 220730 16:56:49 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 39.0s
[D 220730 16:56:50 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 38.0s
[D 220730 16:56:51 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 37.0s
[D 220730 16:56:52 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 36.0s
[D 220730 16:56:53 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 35.0s
[D 220730 16:56:54 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 33.9s
[D 220730 16:56:55 __init__:691] [pid:15028] [127.0.0.1:62001] show float window
[D 220730 16:56:56 __init__:678] [pid:15028] [127.0.0.1:62001] uiautomator-v2 is starting ... left: 32.3s
[I 220730 16:56:56 __init__:638] [pid:15028] [127.0.0.1:62001] uiautomator back to normal
{'currentPackageName': 'com.android.settings', 'displayHeight': 1920, 'displayRotation': 0, 'displaySizeDpX': 540, 'displaySizeDpY': 960, 'displayWidth': 1080, 'productName': 'SM-N960F', 'screenOn': True, 'sdkInt': 22, 'naturalOrientation': True}
- 本文介绍了Uiautomator2初始化。
- 如果觉得文章对你有用处,记得
点赞
收藏
转发
一波哦,博主也支持为铁粉丝制作专属动态壁纸哦~
? 往期优质文章分享
python3调用百度翻译接口
C++读取python脚本中的dictionary字典变量以及它的键值对
Qt中的套件提示no complier set in kit和no debugger,出现黄色感叹号问题解决(MSVC2017)
Python+selenium 自动化 - 实现自动导入、上传外部文件(不弹出windows窗口)
? 优质教程分享 ?
- ?如果感觉文章看完了不过瘾,可以来我的其他 专栏 看一下哦~
- ?比如以下几个专栏:Python实战微信订餐小程序、Python量化交易实战、C++ QT实战类项目 和 算法学习专栏
- ?可以学习更多的关于C++/Python的相关内容哦!直接点击下面颜色字体就可以跳转啦!
? 资料白嫖,温馨提示 ?
关注下面卡片即刻获取更多编程知识,包括各种语言学习资料,上千套PPT模板和各种游戏源码素材等等资料。更多内容可自行查看哦!
转载请注明:虚坏叔叔 » app小程序手机端Python爬虫实战03-uiautomater2项目初始化