#coding:utf-8from appium import webdriverfrom time import sleepimport randomdesired_caps={ "platformName":"android", "platformVersion":"7.1.1", "deviceName":"your_device_name", "appPackage":"com.songheng.eastnews", "appActivity":"com.oa.eastfirst.activity.WelcomeActivity", "noReset":"True"}driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps)sleep(3)def swipe_up(t=500,n=1): """上滑""" size=driver.get_window_size() x1=size['width']*0.5 y1=size['height']*0.85 y2=size['height']*0.15 for j in range(n): driver.swipe(x1,y1,x1,y2,t)def swipe_down(t,n): """下滑""" size=driver.get_window_size() # 开始x坐标 x1=size['width']*0.5 # 开始y坐标 y1=size['height']*0.15 #结束y坐标 y2=size['height']*0.85 for j in range(n): driver.swipe(x1,y1,x1,y2,t)#浏览新闻def look_news(x,y): sleep(8) #点击新闻链接,没有找到比较合适的可利用的属性,只能用坐标了 driver.tap([(x,y)]) sleep(16) #上滑继续看,不然任务栏进度会暂停 swipe_up(t=500,n=1) sleep(10) #上滑继续看,不然任务栏不动 swipe_up(t=500,n=1) sleep(8) #下滑看,走完一次任务栏获得金币 swipe_down(t=500,n=1) sleep(10) #返回新闻页 driver.keyevent('4') sleep(random.randint(2,4)) #上滑,选其他新闻 swipe_up(t=500,n=1)#先定个小目标,跑它一百次for i in range(100): print (i) #推荐 if i <= 20: look_news(500,540) #热点 elif i <= 40: driver.tap([(250, 250)]) sleep(2) look_news(540,680) #视频 elif i <= 60: driver.tap([(400, 250)]) sleep(2) look_news(540,680) #娱乐 elif i < 80: driver.tap([(530, 250)]) sleep(2) look_news("540", "1050") elif i < 100: driver.tap([(530, 260)]) sleep(2) look_news("540", "480") else: driver.quit() 查找可利用的activity和packgage命令: aapt dump badging **.apk 会显示可加载运行的activity