1. Python connects to mobile phones to automatically collect ant forest energy

1. Python connects to mobile phones to automatically collect ant forest energy

1. First, we need to download an ADB DRIVER INSTALL driver installation. If you need it, you can download it from my resources.
Insert picture description here
2. The mobile phone enters the developer mode, and under the usb debugging, select "charging only" to start debugging, insert the usb cable, and turn on the (usb debugging) on ​​the mobile phone

3. Then enter the file you just downloaded. For example, mine is:
C:\Users\18902\Downloads\platform-tools>
and enter: python -m uiautomator2 init
This step is actually to install the apk on our mobile phone. Remember to go to the mobile phone to agree to install
Insert picture description here

Insert picture description here
4. After these things are configured, we need to install the uiautomator2 library in pycharm. Below is a mirror installation link

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

5. After that is the code implementation!

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. Run the test
Insert picture description here

It seems that the video cannot be uploaded! ! !
Insert picture description here
Insert picture description here
God! Really great! ! ! Every time I always see Alipay reminding who is stealing energy again. This time I don’t have to manually collect energy by myself! ! ! Everyone, try it out hahahaha

Guess you like

Origin blog.csdn.net/weixin_43890515/article/details/113964618
Recommended