阅读本文大概需要 3.5 分钟。
打开支付宝;
打开蚂蚁森林;
先收取自己的能量;
跳到下一个有能量的人那边;
收取 ta 的能量
重复 4 和 5,直到没有能量可以“偷”
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">pip install --upgrade --pre uiautomator2</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">import uiautomator2 as u2</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">import time</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">import random</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"># d = u2.connect() # 有线连接,手机需要插电脑上 </span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">d = u2.connect("192.168.0.108") #通过无线连接,电脑和手机需要在同一个局域网内,并且需要先用有线的方式做过初始化</span>
<span class="code-snippet_outer"><br></span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"># d.app_stop("com.eg.android.AlipayGphone") </span>
<span class="code-snippet_outer"><br></span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">print("打开支付宝")</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">d.app_start("com.eg.android.AlipayGphone")</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">time.sleep(2) ## 休眠2s等待支付宝完全启动</span>
<span class="code-snippet_outer"><br></span>
<span class="code-snippet_outer"><br></span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">print("打开蚂蚁森林,等待5s……")</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">d(text="蚂蚁森林").click()</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">time.sleep(5) ## 我手机比较卡,进入蚂蚁森林后还需要几秒钟才能完全加载完 </span>
<span class="code-snippet_outer"><br></span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">def collectEnergy(cnt):</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> print("开始第%d次偷能量!" % cnt)</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> # 开始扫描点击有能力出现的区域 </span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> for x in range(150,1000,150):</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> for y in range(600,900,150):</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> d.long_click(x + random.randint(10,20), y + random.randint(10,20), 0.1)</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> time.sleep(0.01)</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> if cnt != 1:</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> d.click(536,1816)</span>
<span class="code-snippet_outer"><br></span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">cnt = 1</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">while True:</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> collectEnergy(cnt)</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> a = d.xpath("//*[@resource-id='J_tree_dialog_wrap']").get().bounds </span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> d.click(1000, a[3]-80) # 找能量按钮的坐标 </span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> ## 如果页面出现了“返回我的森林”说明已经没有能量可偷了,结束</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> if d.xpath('//*[@text="返回我的森林"]').click_exists(timeout=2.0):</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> break</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> cnt += 1</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">print("###结束###")</span>
<span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;"># d.app_stop("com.eg.android.AlipayGphone") # 退出支付宝</span>
<span class="code-snippet_outer"><br></span>
推荐阅读:
内容包含Java基础、JavaWeb、MySQL性能优化、JVM、锁、百万并发、消息队列、高性能缓存、反射、Spring全家桶原理、微服务、Zookeeper、数据结构、限流熔断降级……等技术栈!
⬇戳阅读原文领取! 朕已阅
文章收集整理于网络,请勿商用,仅供个人学习使用,如有侵权,请联系作者删除,如若转载,请注明出处:http://www.cxyroad.com/1900.html