Python+uiautomator2实现自动刷抖音视频

工具准备

  1. Python3.7.7
  2. adb(Android debug bridge)
  3. uiautomatorviewer

安装adb

官网地址:developer.android.google.cn/studio/comm…

下载好解压后设置环境变量即可

image

安装uiautomatorviewer

调试工具

  1. 手机通过USB连接到电脑上开启开发者选项和USB调试

  2. 在电脑上通过adb devices -l命令查看已连接的设备image

  3. 打开UIAutomatorViewer连接手机即可image

Python安装uiautomator2


pip install --pre -U uiautomator2

  • 给设备安装atx-agent

python -m uiautomator2 init


注意打开设备,允许uiautomator.apk的安装

image

编写主程序

  • 定位抖音位置image

几种定位方式如下: text:a(text=“抖音极速版”).click() resourceid:a(resourceId=“com.smartisanos.clock:id/text_stopwatch”).click() classname:a(className=“android.widget.TextView”).click() description :a(description="…").click()


import uiautomator2 as d import time def douyin(): #通过usb连接 a=d.connect_usb('3d51a18c') # 打开抖音 a(text="抖音极速版").click() while True: time.sleep(10) # 滑动视频 a.swipe(313,1370,313,110) if __name__=='__main__': douyin()


点击运行即可

posted @ 2026-03-19 10:08  wisilian21  阅读(33)  评论(0)    收藏  举报