当前位置 博文首页 > python连接手机自动搜集蚂蚁森林能量的实现代码

    python连接手机自动搜集蚂蚁森林能量的实现代码

    作者:_yummy_ 时间:2021-07-21 18:42

    1、首先我们需要下载一个ADB DRIVER INSTALL驱动安装。需要的可以到我的资源那里下载

    在这里插入图片描述

    2、手机进入开发者模式,usb调试下面选择“仅为充电” 开始调试,插入usb线,手机把(usb调试)打开

    3、之后进入刚刚下载的文件里面,比如我的就是:
    C:\Users\18902\Downloads\platform-tools>
    然后输入:python -m uiautomator2 init

    这个步骤其实就是在我们的手机上安装apk。记住要去手机操作同意安装

    在这里插入图片描述

    在这里插入图片描述

    4、这些东西都配置好之后我们需要到pycharm里面安装uiautomator2库。下面是一个镜像安装链接

    pip install --upgrade uiautomator2 -i https://pypi.tuna.tsinghua.edu.cn/simple

    5、之后便是代码实现啦!

    import uiautomator2 as u2
    import time
    import random
    #手机与电脑之间有线连接
    d=u2.connect()
    #打开支付宝
    d.app_start("com.eg.android.AlipayGphone")
    #休眠2s等待支付宝完全启动
    time.sleep(4)
    print("打开蚂蚁森林,等待5s……")
    d(text="蚂蚁森林").click()
    time.sleep(5)
    
    def collectEnergy(cnt):
     print("开始第%d次偷能量:"%cnt)
     #开始扫描点击有能力出现的区域
     for x in range(150,1000,150):
      for y in range(600,900,150):
       d.long_click(x+random.randint(10,20),y+random.randint(10,20),0.1)
       time.sleep(0.01)
       if cnt!=1:
        d.click(536,1816)
    cnt=1
    while True:
     collectEnergy(cnt)
     a = d.xpath("//*[@resource-id='J_tree_dialog_wrap']").get().bounds
     d.click(1000, a[3] - 80) # 找能量按钮的坐标
     #如果页面出现了“返回我的森林”说明已经没有能量可偷了,结束
     if d.xpath('//*[@text="返回我的森林"]').click_exists(timeout=2.0):
      break
     cnt+=1
    print("###结束###")

    6、运行测试

    在这里插入图片描述

    视频好像上传不了!!!

    在这里插入图片描述

    在这里插入图片描述

    天呐!真实太棒啦!!!每次总是看到支付宝提示谁谁谁又来偷能量了。这次都不用我自己手动收能量了!!!大家快动手试起来哈哈哈哈

    jsjbwy
    下一篇:没有了