python+appium自动刷抖音视频

python+appium自动刷抖音视频

使用python和appium自动刷短视频的程序,适用于抖音、抖音极速版以及拼多多视频,注意仅供学习测试使用,不得用于其他用途。

程序当前能够自动打开指定程序,并使用driver.swipe实现自动刷视频,时间间隔是video_length=10加上一个随机数delta=random.uniform(-1, 1.5) ,后续可以获取视频的时长,根据视频时长确定刷视频的间隔

另外,还有程序运行过程中可能出现的弹窗需要处理,如青少年提醒,拼多多弹出的领红包窗口等。
python和appium所需运行环境需要自行配置。
程序源码如下:

from appium import webdriver
import threading
import time
import random
import copy  # 导入copy模块
from selenium.webdriver.support.ui import WebDriverWait
from adbUtil import AdbUtil  # 导入 AdbUtil 类
from selenium.webdriver.common.by import By

class Swipe_Vedio(threading.Thread):
    def __init__(self,desired_caps,type='dy'):
       threading.Thread.__init__(self)
       print(desired_caps)
       print('启动程序...1')          
       self.desired_caps=desired_caps
       self.type=type      
    def run(self):
        #连接        
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', self.desired_caps)           
    #   设置等待
        self.wait = WebDriverWait(self.driver, 400)   
        print('连接完毕')  
        #如果是拼多多程序,自动点击多多视频按键
        if self.type=='pdd':
           print('pdd视频')
           self.driver.find_element(By.XPATH, '//android.widget.RelativeLayout[@content-desc="多多视频1"]').click()
        #刷视频程序                 
        self.swipeVedio(self.driver)          
    def swipeVedio(self,driver):
    #    driver=self.driver
       current_thread = threading.current_thread()
       size = driver.get_window_size()
        # 屏幕的宽
       width = size['width']
        # 屏幕的高
       height = size['height']
        # 屏幕中心坐标
       x1 = width / 2
        # 屏幕y轴的10分之6
       y1 = height / 10 * 6
        # 向上滑动的y轴终点坐标
       y2 = height / 10
        # app开启之后点击一次屏幕,确保页面的展示
       driver.tap([(x1, y2)]) 
       print('shua>>>>')
       videoNums=0     
       while 1:
       #获取视频长度
         video_length=10
         #随机一个数
         delta=random.uniform(-1, 1.5)
         #保留两位小数
         delta=round(delta,2)
         sleepTime=video_length+delta
         time.sleep(sleepTime)
         driver.swipe(x1, y1, x1, y2, 200)
         videoNums+=1
         print(f'{current_thread}已刷视频数>>>{videoNums}')
if __name__ == '__main__':
    #抖音
    desired_caps = { 'platformName': 'Android', 
                'deviceName': '414b333045553398', 
                'platformVersion': '10', 
                'appPackage': 'com.ss.android.ugc.aweme',
                  'appActivity': 'com.ss.android.ugc.aweme.splash.SplashActivity',
                  'noReset':'true' ,
                   'fullReset':'false'  }   
    #设备名,可以使用命令adb devices查看
    devices=['414b333045553398','514b5553395'] 
   
    # 创建多个线程
    threads = []   
    for i in devices:
        temp_caps = copy.deepcopy(desired_caps_lite)
        temp_caps['deviceName']=i
        thread = Swipe_Vedio(temp_caps,'dy')
        thread.start()
        threads.append(thread)
    # 等待所有线程完成
    for thread in threads:
       thread.join()
    print("All threads have finished")'] 
    
  #需要刷抖音极速版及拼多多视频,只需把desired_caps进行修改
    #抖音极速版
    desired_caps = { 'platformName': 'Android', 
                'deviceName': '414b333045553398', 
                'platformVersion': '10', 
                'appPackage': 'com.ss.android.ugc.aweme.lite',
                  'appActivity': 'com.ss.android.ugc.aweme.splash.SplashActivity',
                  'noReset':'true' ,
                   'fullReset':'false'  }
    #拼多多
    desired_caps = { 'platformName': 'Android', 
                'deviceName': '414b333045553398', 
                'platformVersion': '9', 
                'appPackage': 'com.xunmeng.pinduoduo',
                  'appActivity': '.ui.activity.MainFrameActivity',
                  'noReset':'true' ,
                   'fullReset':'false'  }
  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值