快手批量发布作品工具,自动上传视频发布软件,python实现自动脚本

简介: 这个脚本实现了快手批量上传视频的功能,包含登录、上传视频、添加描述和发布等完整流程

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

这个脚本实现了快手批量上传视频的功能,包含登录、上传视频、添加描述和发布等完整流程。使用时需要安装Chrome浏览器和对应版本的chromedriver,并将视频文件放在指定文件夹中。

import os
import time
import logging
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException, NoSuchElementException

class KuaiShouUploader:
def init(self, username, password, video_folder):
self.username = username
self.password = password
self.video_folder = video_folder
self.setup_logging()
self.driver = self.setup_driver()

def setup_logging(self):
    logging.basicConfig(
        filename='kuai_shou_uploader.log',
        level=logging.INFO,
        format='%(asctime)s - %(levelname)s - %(message)s'
    )
    self.logger = logging.getLogger(__name__)

def setup_driver(self):
    options = webdriver.ChromeOptions()
    options.add_argument('--disable-notifications')
    options.add_argument('--disable-infobars')
    options.add_argument('--disable-extensions')
    options.add_argument('--disable-gpu')
    options.add_argument('--no-sandbox')
    options.add_argument('--window-size=1920,1080')

    service = Service(executable_path='chromedriver')
    driver = webdriver.Chrome(service=service, options=options)
    driver.implicitly_wait(10)
    return driver

def login(self):
    self.logger.info("开始登录快手账号")
    self.driver.get('https://www.kuaishou.com')

    try:
        login_button = WebDriverWait(self.driver, 20).until(
            EC.element_to_be_clickable((By.XPATH, '//button[contains(text(),"登录")]'))
        )
        login_button.click()

        # 切换到账号密码登录
        switch_method = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.XPATH, '//div[contains(text(),"账号密码登录")]'))
        )
        switch_method.click()

        # 输入用户名和密码
        username_input = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.XPATH, '//input[@placeholder="请输入手机号/邮箱"]'))
        )
        username_input.send_keys(self.username)

        password_input = self.driver.find_element(By.XPATH, '//input[@placeholder="请输入密码"]')
        password_input.send_keys(self.password)

        # 点击登录按钮
        submit_button = self.driver.find_element(By.XPATH, '//button[contains(text(),"登录")]')
        submit_button.click()

        # 等待登录成功
        WebDriverWait(self.driver, 30).until(
            EC.presence_of_element_located((By.XPATH, '//div[contains(@class,"user-info")]'))
        )
        self.logger.info("登录成功")
        return True

    except Exception as e:
        self.logger.error(f"登录失败: {str(e)}")
        return False

def upload_video(self, video_path, description):
    self.logger.info(f"开始上传视频: {video_path}")
    try:
        # 打开发布页面
        self.driver.get('https://www.kuaishou.com/publish')

        # 上传视频文件
        upload_input = WebDriverWait(self.driver, 30).until(
            EC.presence_of_element_located((By.XPATH, '//input[@type="file"]'))
        )
        upload_input.send_keys(os.path.abspath(video_path))

        # 等待视频上传完成
        WebDriverWait(self.driver, 300).until(
            EC.invisibility_of_element_located((By.XPATH, '//div[contains(text(),"上传中")]'))
        )

        # 输入视频描述
        desc_input = WebDriverWait(self.driver, 20).until(
            EC.presence_of_element_located((By.XPATH, '//textarea[@placeholder="添加描述..."]'))
        )
        desc_input.send_keys(description)

        # 点击发布按钮
        publish_button = WebDriverWait(self.driver, 20).until(
            EC.element_to_be_clickable((By.XPATH, '//button[contains(text(),"发布")]'))
        )
        publish_button.click()

        # 等待发布完成
        WebDriverWait(self.driver, 60).until(
            EC.presence_of_element_located((By.XPATH, '//div[contains(text(),"发布成功")]'))
        )

        self.logger.info(f"视频发布成功: {video_path}")
        return True

    except Exception as e:
        self.logger.error(f"视频上传失败 {video_path}: {str(e)}")
        return False

def batch_upload(self):
    if not os.path.exists(self.video_folder):
        self.logger.error(f"视频文件夹不存在: {self.video_folder}")
        return False

    video_files = [f for f in os.listdir(self.video_folder) if f.endswith(('.mp4', '.mov', '.avi'))]
    if not video_files:
        self.logger.error("文件夹中没有找到视频文件")
        return False

    if not self.login():
        return False

    for idx, video_file in enumerate(video_files, 1):
        video_path = os.path.join(self.video_folder, video_file)
        description = f"这是我的第{idx}个作品 #{video_file.split('.')[0]}"

        if self.upload_video(video_path, description):
            self.logger.info(f"成功上传第{idx}个视频: {video_file}")
        else:
            self.logger.warning(f"上传第{idx}个视频失败: {video_file}")

        # 间隔一段时间再上传下一个
        time.sleep(10)

    return True

def close(self):
    self.driver.quit()
    self.logger.info("浏览器已关闭")

if name == "main":

# 配置参数
USERNAME = "your_username"
PASSWORD = "your_password"
VIDEO_FOLDER = "videos"

uploader = KuaiShouUploader(USERNAME, PASSWORD, VIDEO_FOLDER)
try:
    uploader.batch_upload()
except Exception as e:
    uploader.logger.error(f"程序运行出错: {str(e)}")
finally:
    uploader.close()
相关文章
|
26天前
|
存储 缓存 测试技术
理解Python装饰器:简化代码的强大工具
理解Python装饰器:简化代码的强大工具
|
2月前
|
程序员 测试技术 开发者
Python装饰器:简化代码的强大工具
Python装饰器:简化代码的强大工具
158 92
|
14天前
|
机器学习/深度学习 编解码 Python
Python图片上采样工具 - RealESRGANer
Real-ESRGAN基于深度学习实现图像超分辨率放大,有效改善传统PIL缩放的模糊问题。支持多种模型版本,推荐使用魔搭社区提供的预训练模型,适用于将小图高质量放大至大图,放大倍率越低效果越佳。
|
2月前
|
人工智能 自然语言处理 安全
Python构建MCP服务器:从工具封装到AI集成的全流程实践
MCP协议为AI提供标准化工具调用接口,助力模型高效操作现实世界。
437 1
|
24天前
|
算法 安全 数据安全/隐私保护
Python随机数函数全解析:5个核心工具的实战指南
Python的random模块不仅包含基础的随机数生成函数,还提供了如randint()、choice()、shuffle()和sample()等实用工具,适用于游戏开发、密码学、统计模拟等多个领域。本文深入解析这些函数的用法、底层原理及最佳实践,帮助开发者高效利用随机数,提升代码质量与安全性。
121 0
|
16天前
|
数据采集 机器学习/深度学习 人工智能
Python:现代编程的首选语言
Python:现代编程的首选语言
187 102
|
16天前
|
数据采集 机器学习/深度学习 算法框架/工具
Python:现代编程的瑞士军刀
Python:现代编程的瑞士军刀
191 104
|
16天前
|
人工智能 自然语言处理 算法框架/工具
Python:现代编程的首选语言
Python:现代编程的首选语言
180 103
|
16天前
|
机器学习/深度学习 人工智能 数据挖掘
Python:现代编程的首选语言
Python:现代编程的首选语言
128 82
|
16天前
|
数据采集 机器学习/深度学习 人工智能
Python:现代编程的多面手
Python:现代编程的多面手
30 0

推荐镜像

更多