刷视频脚本,抖音快手小红书,自动看广告刷视频【python】

简介: 这个代码示例展示了如何使用Selenium和PyAutoGUI模拟视频观看行为,包括登录、观看视频

下载地址:https://www.pan38.com/dow/share.php?code=JCnzE 提取密码:7705

这个代码示例展示了如何使用Selenium和PyAutoGUI模拟视频观看行为,包括登录、观看视频、点赞评论等操作。但请注意,实际平台的反爬机制会更复杂,且此类自动化操作违反平台规定。建议仅用于学习自动化测试技术。

import time
import random
import pyautogui
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class VideoAutoWatcher:
def init(self):
self.driver = None
self.platforms = {
'douyin': 'https://www.douyin.com',
'kuaishou': 'https://www.kuaishou.com',
'xiaohongshu': 'https://www.xiaohongshu.com'
}
self.setup_driver()

def setup_driver(self):
    chrome_options = Options()
    chrome_options.add_argument("--window-size=1200,800")
    chrome_options.add_argument("--mute-audio")
    self.driver = webdriver.Chrome(options=chrome_options)

def login(self, platform, username, password):
    print(f"Logging in to {platform}...")
    self.driver.get(self.platforms[platform])
    time.sleep(3)

    # 这里简化了登录流程,实际需要根据平台页面结构调整
    try:
        login_btn = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.XPATH, "//button[contains(text(),'登录')]"))
        )
        login_btn.click()
        time.sleep(2)

        username_field = self.driver.find_element(By.NAME, "username")
        password_field = self.driver.find_element(By.NAME, "password")

        username_field.send_keys(username)
        password_field.send_keys(password)
        password_field.send_keys(Keys.RETURN)
        time.sleep(5)

        print("Login successful!")
        return True
    except Exception as e:
        print(f"Login failed: {str(e)}")
        return False

def watch_videos(self, platform, duration=60, watch_count=10):
    print(f"Starting to watch videos on {platform}...")
    self.driver.get(self.platforms[platform])
    time.sleep(5)

    for i in range(watch_count):
        print(f"Watching video {i+1}/{watch_count}")

        # 模拟观看行为
        self.simulate_watching(duration)

        # 随机滑动到下一个视频
        self.swipe_to_next()

        # 随机间隔
        time.sleep(random.uniform(2, 5))

def simulate_watching(self, duration):
    start_time = time.time()
    while time.time() - start_time < duration:
        # 随机移动鼠标模拟真实观看
        x = random.randint(100, 1000)
        y = random.randint(100, 700)
        pyautogui.moveTo(x, y, duration=0.5)

        # 随机点赞或评论
        if random.random() < 0.1:
            self.like_or_comment()

        time.sleep(random.uniform(1, 3))

def like_or_comment(self):
    try:
        if random.random() < 0.7:
            # 点赞
            like_btn = WebDriverWait(self.driver, 5).until(
                EC.presence_of_element_located((By.XPATH, "//div[contains(@class,'like-btn')]"))
            )
            like_btn.click()
            print("Liked the video")
        else:
            # 评论
            comment_btn = WebDriverWait(self.driver, 5).until(
                EC.presence_of_element_located((By.XPATH, "//div[contains(@class,'comment-btn')]"))
            )
            comment_btn.click()
            time.sleep(1)

            comment_box = self.driver.find_element(By.XPATH, "//textarea")
            comments = ["不错!", "好看", "666", "赞一个", "喜欢这个内容"]
            comment_box.send_keys(random.choice(comments))
            time.sleep(1)

            submit_btn = self.driver.find_element(By.XPATH, "//button[contains(text(),'发送')]")
            submit_btn.click()
            print("Commented on the video")
    except:
        pass

def swipe_to_next(self):
    try:
        # 模拟滑动操作
        pyautogui.moveTo(600, 400, duration=0.5)
        pyautogui.dragTo(600, 200, duration=0.5, button='left')
        time.sleep(1)
    except:
        pass

def close(self):
    if self.driver:
        self.driver.quit()
        print("Browser closed.")

if name == "main":
watcher = VideoAutoWatcher()
try:

    # 示例使用 - 实际需要替换为真实账号
    if watcher.login('douyin', 'your_username', 'your_password'):
        watcher.watch_videos('douyin', duration=30, watch_count=20)
finally:
    watcher.close()
相关文章
|
5月前
|
JSON 缓存 API
深度分析淘宝API接口,用Python脚本实现
本内容深入解析淘宝开放平台 API 的接口设计与 Python 实现,涵盖接口体系、认证机制、签名规则及限流策略,并提供完整的 Python 调用框架,适用于电商系统对接与自动化运营。
|
5月前
|
JSON 算法 API
深度分析小红书城API接口,用Python脚本实现
小红书作为以UGC内容为核心的生活方式平台,其非官方API主要通过移动端抓包解析获得,涵盖内容推荐、搜索、笔记详情、用户信息和互动操作等功能。本文分析了其接口体系、认证机制及请求规范,并提供基于Python的调用框架,涉及签名生成、登录态管理与数据解析。需注意非官方接口存在稳定性与合规风险,使用时应遵守平台协议及法律法规。
|
5月前
|
JSON API 数据安全/隐私保护
【干货满满】分享微店API接口到手价,用python脚本实现
微店作为知名社交电商平台,其开放平台提供商品查询、订单管理等API接口。本文介绍如何通过微店API获取商品到手价(含优惠、券等),涵盖认证机制、Python实现及关键说明。
|
5月前
|
JSON API 数据安全/隐私保护
【干货满满】分享淘宝API接口到手价,用python脚本实现
淘宝开放平台通过API可获取商品到手价,结合商品详情与联盟接口实现优惠计算。需使用AppKey、AppSecret及会话密钥认证,调用taobao.tbk.item.info.get接口获取最终价格。代码示例展示签名生成与数据解析流程。
|
5月前
|
JSON API 数据安全/隐私保护
深度分析苏宁API接口,用Python脚本实现
苏宁易购开放平台提供覆盖商品、订单、库存、门店等零售全链路的API服务,采用RESTful架构与“AppKey+AppSecret+签名”认证机制,支持线上线下一体化业务处理。本文详解其API特性、认证流程及Python调用实现。
|
5月前
|
自然语言处理 安全 API
深度分析洋码头API接口,用Python脚本实现
洋码头是国内知名跨境电商平台,专注于海外商品直购。本文基于其API的通用设计逻辑,深入解析了认证机制、签名规则及核心接口功能,并提供了Python调用示例,适用于商品与订单管理场景。
|
5月前
|
JSON API 数据格式
深度分析易贝API接口,用Python脚本实现
本文深度解析了eBay开放平台的RESTful API接口体系,涵盖其核心功能、OAuth 2.0认证机制、请求规范及限流策略,并基于Python构建了完整的API调用框架。内容包括商品与订单管理接口的实现逻辑、认证流程、错误处理机制及实战调用示例,适用于跨境电商系统开发与多平台集成。
|
5月前
|
JSON 监控 BI
深度分析亚马逊API接口,用Python脚本实现
本内容深度解析亚马逊SP-API接口体系,涵盖商品、订单、库存等核心功能域,详解LWA认证、AWS签名及Python调用实现,适用于跨境电商系统开发与集成。
|
5月前
|
API Python 数据格式
深度分析京东API接口,用Python脚本实现
深度分析京东API接口,用Python脚本实现
|
5月前
|
JSON API 开发者
深度分析微店API接口,用Python脚本实现
微店作为知名移动端电商平台,其开放平台提供丰富的API接口,支持商品、订单、客户及营销管理。本文分析其API核心特性,并提供Python调用示例,助力开发者快速集成业务功能。

推荐镜像

更多