shanghai 现在抢菜之苦,真的有口说不出,每天早上6点,6点半,8点半,体验过的人的都知道,即便手速再快,还是抢不到..... 然后就有了下面的抢菜程序,完全由Python实现,并会附上教程: python3:安装python3环境,并安装依赖: ( mac电脑adb安装:brew install android-platform-tools ) 手机:安卓手机一部或者多部,或者安卓虚拟机一个或者多个 adb:adb安装成功后,在命令行输入adb,会出现以下提示: 当安卓手机和电脑连接之后,再输入:adb devices,就可以看到设备编号,记住这个编号,后面有用。 (如果用的安卓虚拟机,需要注意:需要先执行:adb kill-server,然后再执行:adb start-server,再执行:adb devices,才会显示设备列表) python -m uiautomator2 init 打开美团,并进入购物车页面,确认购物车里是有商品的:(没有商品肯定是不行的,对吧) import os import time import uiautomator2 as u2
# 连接手机 def connect_phone(device_name): d = u2.connect(device_name) if not d.service(\\"uiautomator\\").running(): # 启动uiautomator服务 print(\\"start uiautomator\\") d.service(\\"uiautomator\\").start() time.sleep(2)
if not d.agent_alive: print(\\"agent_alive is false\\") u2.connect() d = u2.connect(device_name) return d
def run(device_name): d = connect_phone(device_name) d.app_start(\\"com.sankuai.meituan\\") count = 1 time_start = time.time()
while True: start = time.time() if d(textContains=\\"结算(\\").exists: print(\\"点击结算\\") d(textContains=\\"结算(\\").click()
if d(text=\\"我知道了\\").exists: print(\\"点击我知道了\\") d(text=\\"我知道了\\").click()
if d(text=\\"返回购物车\\").exists: print(\\"点击返回购物车\\") d(text=\\"返回购物车\\").click()
if d(text=\\"立即支付\\").exists: print(\\"点击立即支付\\") d(text=\\"立即支付\\").click()
if d(text=\\"确认并支付\\").exists: print(\\"点击确认并支付\\") d(text=\\"确认并支付\\").click()
if d(resourceId=\\"btn-line\\").exists: print(\\"确认支付\\") d(resourceId=\\"btn-line\\").click() # mac系统使用语音提示:说抢到菜了,windows请屏蔽 # os.system('say \\"抢到菜了,快来看\\"') break print(\\"本次花费时间:\\", time.time() - start) print(\\"总共花费时间:\\", (time.time() - time_start) / 60, \\"分钟,第\\", count, \\"次\\") count += 1
if __name__ == '__main__': # 此处填设备编号:由1024我的小表妹原创 device_name = \\"b8c282ac\\" run(device_name)
(因为我有两个安卓手机,又另外开了一个安卓虚拟机,所以就是下面效果了,哈哈哈哈哈) 再展示一下抢到的菜吧,同时祝大家早日抢到自己喜欢的菜吧,也希望疫情赶紧结束:
|