一年一度得双11又来了,根据2019的脚本稍作修改,即可完成2020的瞄币任务
用到的库:
os
re
time
通过adb命令下载当前的淘宝页面的布局,获取布局的按钮坐标,然后用adb命令进行点击 仅限安卓手机无需root 使用教程: 1 打开手机的开发者选项(百度教程很简单//设置-连续点击版本号五次即可进入开发者) 2 USB连接电脑(授权秘钥与这台电脑连接) 3 运行脚本,自动检测是否连接了手机 4 打开淘宝,调至领喵币任务界面 5 根据需求填入相应任务的坐标(x,y),可以手动通过开发者选项查看(见置顶文章)或者自动获取坐标 6 等待脚本完成 请勿选择仅充电,adb不识别 其他:
脚本运行过程中请勿翻动手机,尽管可以实时获取当前的任务进度和手机状态,但频繁拉去淘宝xml,会导致未知bug,所以还是保守ui.txt为当前的淘宝布局,其是针对一个手机一个布局坐标不通用(貌似手机尺寸差不多也无所谓),为不同的手机执行脚本需要手动删除ui.txtERROR: null root node returned by UiTestAutomationBridge. 安卓P以上的bug 请无视脚本依赖于adb命令,请在adb同级文件夹下执行 程序依次获取了复杂浏览任务和所有按钮坐标
import os,re
import time
#触摸坐标
def tapXY(x,y,task):
for i in range(task):
os.system('adb shell input tap {} {}'.format(x,y))#触摸店铺按钮
print('---开始任务---')
time.sleep(3)
os.system('adb shell input tap {} {}'.format(1,1))#模拟滑动界面
print('---等待25秒---')
time.sleep(25)
print('---领取完成---')
os.system('adb shell input keyevent 4')
time.sleep(4)
print('第{}任务领取完成'.format(i+1))
print('______________________')
#下载当前活动UI
def downloadUi():
if os.path.exists('ui.txt'):
openUi()
else:
try:
os.system('adb shell uiautomator dump /sdcard/ui.xml')
time.sleep(2)
os.system('adb shell uiautomator dump /sdcard/ui.xml')
os.system('adb pull /sdcard/ui.xml ui.txt')
size=get_FileSize('ui.txt')
if size>=0.03:#第一次获取ui会出现文件非淘宝xml
openUi()
else:
print('xml文件错误正在重新下载,请勿翻动手机界面')
os.remove('ui.txt')
downloadUi()
except:
print('adb连接错误请重新打开')
if os.path.exists('ui.txt'):
os.remove('ui.txt')
#打开ui.txt 寻找坐标
def openUi():
uiText=open('ui.txt',encoding='UTF-8')
uiText=uiText.read()
tapPosition=re.findall(' |