自动完成今年双 11 的喵币任务

2019 双十一,tb 推出了新的活动,商店喵币,看了一下每天都有几个任务来领取喵币,从而升级店铺赚钱,然而对象既想赚红包又不想让我干苦力,遂使用 python 来进行手机自动化操作!💁下面贴一下他的教程

用到的库:

re
os
time

思路:

1, 下载 adb 命令安装包
2, 打开手机开发者选项(点击系统设置,连点 5 次系统版本,即可在辅助功能或其他选项中找到开发者选项,此功能无害,可不必关闭)
3, 在开发者选项中找到 USB 调试打开(反是有 USB 字样选项的全部同意,有提示风险也同意,PS:自己操作鸡毛风险没有,在一些商厦的有免费充电桩,若此充电桩提示请求 USB 调试请拒绝,此行为是风险操作,有可能获取隐私!)
4, 手机连接电脑
5, 将仅限 USB 充电调至 MIDI 模式(部分手机有, 任务栏下拉) (部分手机在仅充电模式下无法连接)
6, 调至 tb 喵币做任务界面
7, 将.py 文件移动至 adb 文件夹目录下
8, 在开发者界面下打开指针位置
9, 填入 X,Y 坐标
10, 运行脚本

import os,re
import time
print('-----ctrl+c终止程序-----------')
task=int(input('请输入任务个数:'))
chose=int(input('请选择自定位[1]或手动输入[2]:'))
print('author:okfu')
list=[]
list1=[]
def go(x,y):		
	for i in range(task+1):
		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'):
			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:#这里两次获取xml,以防获取的第一个为安卓非IDE情况下的xml
				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('错误')
				go_2()						
	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 出现闪退请多次开关程序

自动完成今年双 11 的喵币任务

自动完成今年双 11 的喵币任务

分享结束了,溜了溜了,不要打我