<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          手把手教你收取螞蟻森林能量

          共 2593字,需瀏覽 6分鐘

           ·

          2021-02-18 15:52

          文 |?某某白米飯

          來源:Python 技術(shù)「ID: pythonall」

          支付寶集 5 福讓小編打開了塵封已久的螞蟻森林小程序,它剛出來那會(huì)兒小編也算是一個(gè)重度用戶,看著一直被偷的能量總想以德服人。今天就用 Python + Appium 寫一個(gè)自動(dòng)收取能量的腳本,完成之后再也沒人能從小編手上將能量偷走了。


          啟動(dòng)入口

          還不會(huì)使用 Appium 的小伙伴可以先看看本公眾號(hào)上的《解放雙手,提高生產(chǎn)力,這款神器你值得擁有》學(xué)習(xí)和使用 Appium。

          下面代碼是支付寶的配置文件:

          from?appium?import?webdriver
          from?selenium.webdriver.common.by?import?By
          from?selenium.webdriver.support.ui?import?WebDriverWait
          from?appium.webdriver.common.touch_action?import?TouchAction
          from?selenium.webdriver.support?import?expected_conditions?as?EC

          desired_capabilities?=?{
          ????'platformName':?'Android',??#?操作系統(tǒng)
          ????'deviceName':?'2a254a02',??#?設(shè)備?ID
          ????'platformVersion':?'10.0.10',??#?設(shè)備版本號(hào),在手機(jī)設(shè)置中查看
          ????'appPackage':?'com.eg.android.AlipayGphone',??#?app?包名
          ????'appActivity':?'AlipayLogin',??#?app?啟動(dòng)時(shí)主?Activity
          ????'noReset':?True??#?是否保留?session?信息?避免重新登錄
          }

          driver?=?webdriver.Remote('http://localhost:4723/wd/hub',?desired_capabilities)
          #?設(shè)置等待超時(shí)時(shí)間
          wait?=?WebDriverWait(driver,?60)

          點(diǎn)擊進(jìn)入螞蟻森林

          支付寶上的螞蟻森林的圖標(biāo)按鈕位置每個(gè)人按照各自的習(xí)慣都不相同,小編的圖標(biāo)位置在全部-->最近使用里面,可以用螞蟻森林文字找到圖標(biāo)并點(diǎn)擊。


          #?點(diǎn)擊全部圖標(biāo)
          wait.until(EC.element_to_be_clickable((By.ID,?'com.alipay.android.phone.openplatform:id/more_app_icon'))).click()
          #?找到螞蟻森林
          wait.until(EC.element_to_be_clickable((By.XPATH,?'//android.widget.TextView[contains(@text,?"螞蟻森林")]'))).click()
          time.sleep(1)

          收集能量

          在螞蟻森林中并不能通過用 id 的方式定位到能量球,只能用在能量球可能出現(xiàn)的區(qū)域用坐標(biāo)點(diǎn)擊,start_x,end_x,start_y,end_y 是這個(gè)區(qū)域左上角和右下角的坐標(biāo)位置。


          #?獲取手機(jī)屏幕寬高
          width?=?int(driver.get_window_size()['width'])
          height?=?int(driver.get_window_size()['height'])

          #?收取能量
          def?collect_energy(driver,?width,?height):
          ????#?能量球可能出現(xiàn)的區(qū)域坐標(biāo)
          ????start_x?=?150
          ????end_x?=?900
          ????start_y?=?540
          ????end_y?=?900

          ????for?x?in?range(start_x,?end_x,?50):
          ????????for?y?in?range(start_y,?end_y,?50):
          ????????????x_scale?=?int((int(x)?/?width)?*?width)
          ????????????y_scale?=?int((int(y)?/?height)?*?height)
          ????????????#?點(diǎn)擊指定坐標(biāo)
          ????????????TouchAction(driver).press(x=x_scale,?y=y_scale).release().perform()
          ????print('能量收取完畢')

          收取好友能量

          自己的能量收取完之后,點(diǎn)擊 找能量 進(jìn)入好友的螞蟻森林收取好友的能量,直到出現(xiàn)返回我的森林頁面。

          def?search_energy(driver,?width,?height):
          ????x?=?int((int(1000)?/?width)?*?width)
          ????y?=?int((int(1550)?/?height)?*?height)
          ????#?點(diǎn)擊指定坐標(biāo)
          ????TouchAction(driver).press(x=x,?y=y).release().perform()
          ????time.sleep(1)
          ????is_collected?=?is_element_exist_by_xpath(driver,?'//android.widget.Button[contains(@text,?"返回我的森林")]')
          ????if?is_collected:
          ????????print('能量全部收集完畢')
          ????????return

          ????collect_energy(driver,?width,?height)
          ????search_energy(driver,?width,?height)

          總結(jié)

          用 Appium 很簡單的就將螞蟻森林的能量球自動(dòng)化了,看完這篇文章后希望小伙伴可以活學(xué)活用將其他 APP 應(yīng)用中的重復(fù)的操作也自動(dòng)化,省事又省力。

          -END-


          瀏覽 142
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  日日夜夜狠狠操 | 特级西西444kkk高清视频 | 啪啪五月天| 性少妇69 | 夜夜骚视频网 |