版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
2019双十一,tb推出了新的活动,商店喵币,看了一下每天都有几个任务来领取喵币,从而升级店铺赚钱,然而我既想赚红包又不想干苦力,遂使用python来进行手机自动化操作,目测全网首发!
用到的库:
re
os
time
思路:
- 下载adb命令安装包
- 打开手机开发者选项(点击系统设置,连点5次系统版本,即可在辅助功能或其他选项中找到开发者选项,此功能无害,可不必关闭)
- 在开发者选项中找到USB调试打开(反是有USB字样选项的全部同意,有提示风险也同意,PS:自己操作鸡毛风险没有,在一些商厦的有免费充电桩,若此充电桩提示请求USB调试请拒绝,此行为是风险操作,有可能获取隐私!)
- 手机连接电脑
5. 将仅限USB充电调至MIDI模式(部分手机有,任务栏下拉)(部分手机在仅充电模式下无法连接) - 调至淘宝喵币做任务界面
- 将.py文件移动至adb文件夹目录下
- 在开发者界面下打开指针位置
- 填入X,Y坐标
- 运行脚本
import os,re
import time
print('-----ctrl+c终止程序-----------')
task=int(input('请输入任务个数:'))
chose=int(input('请选择自定位[1]或手动输入[2]:'))
print('author:刘秉哲')
list=[]
list1=[]
def go(x,y):
for i in range(task):
os.system('adb shell input tap {} {}'.format(x,y))#触摸店铺按钮
print('---开始任务---')
time.sleep(4)
os.system('adb shell input tap {} {}'.format(1,1))#模拟滑动界面
print('---等待25秒---')
time.sleep(25)
print('---领取完成---')
time.sleep(4)
os.system('adb shell input keyevent 4')
time.sleep(4)
#os.system('adb shell input tap 518 2202')
print('第{}任务领取完成'.format(i+1))
print('______________________')
def go_2():
try:
print('获取坐标中')
file = os.listdir('.')
if os.path.exists('123.txt'):
#if (i.endswith('.txt')):#判断当前文件是否有123.txt
c=open('123.txt',encoding='UTF-8')
a=c.read()
d=re.search('<node index="2" text="去进店"(.*?)/>',a).groups()
f=re.search(' bounds="(.*?)"',str(d)).groups()
g=re.search('\[(.*?)\]',f[0]).group(1)
list.append(g.split(','))#将坐标添加到列表
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 123.txt')
size=get_FileSize('123.txt')
if size>=0.03:#第一次获取ui会出现文件非淘宝xml
file = os.listdir('.')
c=open('123.txt',encoding='UTF-8')
a=c.read()
d=re.search('<node index="2" text="去进店"(.*?)/>',a).groups()
f=re.search(' bounds="(.*?)"',str(d)).groups()
g=re.search('\[(.*?)\]',f[0]).group(1)
list.append(g.split(','))
print('获取成功')
else:
print('xml文件错误正在重新下载,请勿翻动手机界面')
os.remove('123.txt')
#go_2()
except:
print('错误')
except:
print('error')
def get_FileSize(filePath):
fsize = os.path.getsize(filePath)
fsize = fsize/float(1024 * 1024)
return round(fsize, 2)
if chose==1:
try:
go_2()
print("当前坐标:{},{}".format(list[0][0],list[0][1]))
go(int(list[0][0])+20,int(list[0][1])+20)
except:
print('error')
if chose==2:
x=int(input('请输入任务X坐标:'))
y=int(input('请输入任务y坐标:'))
go(x,y)
PS:代码部分命名仓促,见谅。
脚本1功能自动获取下X,Y坐标,大概率成功,小概率需要自行通过2功能修改。
脚本还有不足之处,欢迎指出
问题与难点:
1 实现tb按钮的自定位
2 小几率出现返回任务界面 20个任务会消失(网速和手机性能影响)
3 部分手机会出现坐标定位后,手机无反应,请根据提示的当前坐标,选择2功能,然后将坐标数增减10进行调试
4 error: device not found :手机没有正确连接至电脑(检查adb)
5 检查当前文件夹下的123.TXT 的大小是否在30KB以上,在10KB一下说明获取失败,重新打开软件获取(未知bug)
6 ERROR: null root node returned by UiTestAutomationBridge. 安卓P以上的bug 请多次开关程序
7 脚本不可与adb文件夹(platform-tools)分离,否则无法运行!
8 出现闪退请多次开关程序
2功能可以用于20个任务下面的其他浏览任务,坐标可在123.txt中找到也可在开发者指针位置定位,这里不在赘述。
这里也有封装成exe的,可直接使用,欢迎体验:
https://www.lanzous.com/i6yu56b
adb组件单独下载:
https://www.lanzous.com/i6yfxmf
如果对你有用,就点个赞吧!