福利:appium+selenium+python 模拟手工点击趣头条(app赚钱软件)

最近发现网上有很火的读新闻赚钱的app,于是自己写了一个小脚本,模拟手工操作,点击新闻阅读新闻

使用python语言+真机

下面直接上源码

# coding=utf-8
from appium import webdriver
import time, os


class news:
    def __init__(self):
        desired_caps = {}
        desired_caps['noReset'] = 'True'

        # PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__), p))

        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '8.1.0'
        desired_caps['deviceName'] = '自己的设置名'
        # desired_caps['platformVersion'] = '4.4.2'
        # desired_caps['deviceName'] = '127.0.0.1:62001'
        desired_caps['appPackage'] = 'com.jifen.qukan'
        desired_caps['appWaitActivity'] = 'com.jifen.qkbase.main.MainActivity'
        desired_caps['appActivity'] = 'com.jifen.qkbase.main.MainActivity'
        # desired_caps['app'] = PATH(r"C:\Users\zhou\Downloads\com.jifen.qukan_3.9.6.000.0110.1453_liqucn.com.apk")

        time.sleep(6)
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
        # 阅读新闻
        time.sleep(4)

    # driver.find_elements_by_xpath("//*[@resource-id='com.jifen.qukan:id/aas']")[1].click()
    # guanggao=driver.find_element_by_id('com.jifen.qukan:id/aen')
    def getSize(self):  # 获取当前的width和height的x、y的值
        x = self.driver.get_window_size()['width']  # width为x坐标
        y = self.driver.get_window_size()['height']  # height为y坐标
        return (x, y)

    def swipeUp(self, t):  # 当前向上滑动swipeup
        l = self.getSize()
        x1 = int(l[0] * 0.5)
        y1 = int(l[1] * 0.75)
        y2 = int(l[1] * 0.25)
        try:
            self.driver.swipe(x1, y1, x1, y2, 500)  # 设置时间为500
        except:
            self.driver.press_keycode(4)


    def click_news(self):
        for i in range(1,100):
            time.sleep(3)
            self.swipeUp(9000)
            time.sleep(3)
            elements= self.driver.find_elements_by_xpath("//*[@resource-id='com.jifen.qukan:id/aas']")
            print(len(elements))
            try:
                self.driver.find_elements_by_xpath("//*[@resource-id='com.jifen.qukan:id/aas']")[0].click()
            except:
                self.swipeUp(3000)
                self.driver.find_elements_by_xpath("//*[@resource-id='com.jifen.qukan:id/aas']")[1].click()

            time.sleep(10)
            self.swipeUp(5000)
            time.sleep(10)
            self.swipeUp(5000)
            time.sleep(10)
            self.swipeUp(5000)
            time.sleep(10)
            self.swipeUp(5000)
            time.sleep(10)
            self.swipeUp(5000)
            time.sleep(10)
            self.driver.press_keycode(4)
        self.driver.quit()
if __name__ == '__main__':
    news = news()
    news.click_news()

 

写的比较简单,有待优化,大家可以多多提意见!

下面附一个,趣头条的邀请码:A405824289,大家想试试的,可以用的邀请码哈,谢谢照顾

你可能感兴趣的:(python小程序,自动化)