一年一度得双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('<node index="0" text="浏(.*?)/>',uiText)#找到所有去浏览坐标 for i in tapPosition: task=re.search('\[(.*?)\]',i).group() taskName=re.search('(.*)" resource-id=',i).group(1) print('任务名称:浏'+taskName+' 坐标:'+task) print('按钮坐标(排列顺序依次往下)') buttons=re.findall('<node index="1" text="去(.*?)/>',uiText) for i in buttons: task=re.search('\[(.*?)\]',i).group() taskName=re.search('(.*)" resource-id=',i).group(1) print('去'+taskName+' 坐标:'+task) print('以上是[去浏览/完成/搜索/开通]按钮坐标和任务坐标,请根据任务选取触摸坐标') print('---------------------------') #文件大小 def get_FileSize(filePath): fsize = os.path.getsize(filePath) fsize = fsize/float(1024 * 1024) return round(fsize, 2) if __name__ == '__main__': print('2020TB瞄币自动完成脚本 ctrl+C退出脚本') print('当前连接设备:') if os.system('adb shell getprop ro.product.model')<0: print('未检测到手机!' ) exit() print('--------------------------------------') while 1: flag=int(input('1.自定义X,Y坐标 \n2.自动获取坐标\n请输入序号:')) if flag==1: task=int(input('请输入任务个数:')) x=int(input('请输入任务X坐标:')) y=int(input('请输入任务y坐标:')) tapXY(x,y,task) if flag==2: downloadUi() task=int(input('请输入任务个数:')) x=int(input('请输入任务X坐标:')) y=int(input('请输入任务y坐标:')) startTime=time.time() tapXY(x,y,task) overTime=time.time() print('耗时:'+str(int(overTime-startTime))+'s')adb下载:
lanzous.com/i71gllg打包exe稍后上传
其他信息见置顶文章 如果对你有用,那就点个赞吧!
采用随机休眠时间+随机屏幕滑动 将tapXY函数替换:
def tapXY(x,y,task): for i in range(task): os.system('adb shell input tap {} {}'.format(x,y))#触摸店铺按钮 print('---开始任务---') time.sleep(3) #随机生成触摸点 X Y tapx=random.randint(1,500) tapy=random.randint(1,500) print(tapx,tapy) #os.system('adb shell input tap {} {}'.format(tapx,tapy))#模拟点击界面 os.system('adb shell input swipe {} {} {} {}'.format(tapx,tapx,tapy,tapy))#模拟滑动界面 #随机休眠 sleeptime=random.randint(19,25) print(f'---等待{sleeptime}秒---') time.sleep(sleeptime) print('---领取完成---') os.system('adb shell input keyevent 4') time.sleep(random.randint(1,4)) print('第{}任务领取完成'.format(i+1)) print('______________________')也可以修改swipe滑动命令不停的向下滑动手机界面(部分有直播间任务可能无法适用)
os.system('adb shell input swipe {} {} {} {}'.format(tapx,tapx,tapy,tapy))#模拟滑动界面或加入步骤返回到淘宝首页然后再点进去淘宝喵币界面,如此反复亦可防封
