淘宝里的淘金币有很多任务可以做,做了之后增加第二天获取的淘金币数量,为了得到更多的淘金币,我做了一个脚本,辅助做任务。
import os
import time
import random
import re
from appium import webdriver
desired_caps = {
'platformName': 'Android', # 被测手机是安卓
'deviceName': 'xxx', # 设备名,安卓手机可以随意填写
'appPackage': 'com.taobao.taobao', # 启动APP Package名称
'appActivity': 'com.taobao.tao.TBMainActivity', # 启动Activity名称
'noReset': True, # 不要重置App
}
# 连接Appium Server,初始化自动化环境
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def enter_the_evnt_page():
driver.tap([(546, 971)]) # 点击领淘金币
time.sleep(2)
driver.tap([(520,1335)]) # 点击赚金币
time.sleep(3)
receive_award()
def get_activity():
p = os.popen('adb shell dumpsys window windows | findstr "Current"')
result = p.read()
pat = r'/(.*?)}'
activity = re.search(pat, result)
if activity:
#print(activity.group(1))
pass
else:
print("没有查找到")
return activity.group(1)
def do_browse_task():
'''做浏览任务'''
activity = get_activity()
if activity == 'com.taobao.taolive.room.TaoLiveVideoActivity':
time.sleep(25)
elif activity == 'com.taobao.browser.BrowserActivity':
time.sleep(15) # 其他浏览任务只要13秒就可以了,淘宝人生要长一点
elif activity == 'com.taobao.browser.exbrowser.BrowserUpperActivity':
print("任务未正常进入")
elif activity == 'com.alibaba.triver.container.TriverMainActivity':
time.sleep(15)
else:
print("未知页面")
time.sleep(13)
def find_browsing_tasks():
activity = get_activity()
assert activity == 'com.taobao.browser.exbrowser.BrowserUpperActivity'
try:
driver.swipe(538,1671,500,1100,500)
driver.find_element_by_xpath("//*[@text='浏览10s 立得']").click()
time.sleep(2) # 点击后等待下,不然获取activity可能出错
except:
print("未找到浏览10s的任务")
driver.swipe(538,1671,500,1100,500)
driver.find_element_by_xpath("//*[@text='浏览10s 立得']").click()
time.sleep(2) # 点击后等待下,不然获取activity可能出错
def return_evnt_page():
os.system("adb shell input keyevent 4")
time.sleep(2)
activity = get_activity()
assert activity == 'com.taobao.browser.exbrowser.BrowserUpperActivity'
def receive_award():
driver.tap([(945,765)]) #点击一键领取
time.sleep(2)
def do_the_task():
enter_the_evnt_page()
for i in range(10):
find_browsing_tasks()
do_browse_task()
return_evnt_page()
receive_award()
def test_swipe():
enter_the_evnt_page()
driver.swipe(538,1671,500,1100,500)
do_the_task()
目前有的问题是:
- 不是很稳定,因为模拟操作手机,总会遇到各种各样的问题。
- 第一页的任务基本能完成,但到下一页就不好实现了。
- 如果任务特别靠下,可能会出现找到任务后无法点击的情况。