参考链接:
YYDS!用Python就能轻松控制你的手机_欣一2002的博客-优快云博客
一份超全超详细的 ADB 用法大全_adb install参数_wxtx2020的博客-优快云博客
前置条件:
- USB连接手机,打开USB调试开关,以及手机触摸坐标数据。
- pycharm终端安装pure-python-adb包。
- 终端或cmd输入:
adb start-server
4.找你要打开的应用的Activity,我是先在手机打开一下这个应用,再在终端或cmd输入:
adb shell dumpsys activity top | findstr "ACTIVITY"
Python脚本:
from ppadb.client import Client as AdbClient
import time
def connect():
client = AdbClient(host='127.0.0.1', port=5037) # 创建连接,5037是默认端口号
devices = client.devices() # 连接设备
if len(devices) == 0: # 查询所有设备
print("no devices found")
quit()
device = devices[0] # 获取设备
print(len(devices), devices) # 打印连接设备数量和连接对象
return device, client
if __name__ == '__main__':
device, client = connect()
device.shell('input keyevent 82') # 电源键
device.shell('input swipe 300 1000 300 500') # 上划解锁
# 打开手Y(这里要替换成你要打开的应用的activity)
device.shell(
'am start -n com.duowan.mobile/com.yy.mobile.plugin.homepage.ui.home.HomeActivity 3704e83 pid=14977')
time.sleep(5) # 等待手Y打开
device.input_tap(230, 907) # 点击进入直播间
time.sleep(5)
# 滑动切换直播间20次,切换一次暂停3秒加载
for i in range(1, 21):
device.input_swipe(300, 1000, 300, 500, 500)
time.sleep(3)
bat批处理脚本:
adb shell input keyevent 82
adb shell input swipe 300 1000 300 500
adb shell am start -n com.duowan.mobile/com.yy.mobile.plugin.homepage.ui.home.HomeActivity 3704e83 pid=14977
timeout /T 5
adb shell input tap 230 907
timeout /T 5
for /l %%i in (1,1,20) do (
adb shell input swipe 300 1000 300 500
timeout /T 3
)
bat批处理文件运行方法:
在记事本上写好代码,后缀改为.bat,保存后双击即可运行。