Frontend Development 6 min read

Python Selenium Automation for Publishing Short Videos on Qutoutiao

This tutorial demonstrates how to use Python and Selenium to automate the uploading and publishing of short videos on the Qutoutiao platform, covering browser attachment, video and cover file handling, form filling, and full source code examples.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Python Selenium Automation for Publishing Short Videos on Qutoutiao

The article is part of a series that introduces automated publishing for major short‑video platforms, and this installment focuses on the Qutoutiao platform. It explains the overall workflow and shows the expected results such as video playback and cover display.

Implementation Process

1. Attach to an already running Chrome browser – By launching Chrome with remote debugging (port 5003) and creating a webdriver.ChromeOptions() object that points to the debugger address, the script can reuse the logged‑in session and skip repeated logins.

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress", "127.0.0.1:5003")
driver = webdriver.Chrome(options=options)

2. Upload video and cover – The script locates the file input elements via XPath, sends the local file paths, and polls the page until an "upload successful" message appears. After the video is uploaded, it clicks the UI to choose a custom cover image and confirms the selection.

# Upload video
driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_mp4)
# Wait for upload to finish
while True:
    time.sleep(3)
    try:
        driver.find_element_by_xpath('//*[contains(text(),"上传成功")]')
        break
    except Exception:
        print("视频还在上传中···")
print("视频已上传完成!")
# Add cover
time.sleep(1)
driver.find_element_by_xpath('//*[@class="el-upload"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[text()="自定义封面"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[text()="选择图片"]/../..//input[@type="file"]').send_keys(path_cover)
time.sleep(3)
driver.find_element_by_xpath('//*[text()="确定"]').click()

3. Full source code – The complete script defines paths for video and cover files, extracts the first matching .mp4 and image files, fills in title, description, category, and tags, and finally triggers the publish action (commented out for safety). The code demonstrates error handling for missing files and uses Keys.ENTER to confirm tag entries.

import selenium
from selenium import webdriver
import pathlib, time
from selenium.webdriver.common.keys import Keys

catalog_mp4 = r"C:\Users\Administrator\Desktop\视频发布"
describe = "裸眼3D看蜘蛛侠 #搞笑 #电影 #视觉震撼"
options = webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress", "127.0.0.1:5003")
driver = webdriver.Chrome(options=options)

# Locate video and cover files
path = pathlib.Path(catalog_mp4)
for i in path.iterdir():
    if ".mp4" in str(i):
        path_mp4 = str(i)
        break
for i in path.iterdir():
    if ".png" in str(i) or ".jpg" in str(i):
        path_cover = str(i)
        break

def publish_qutoutiao():
    driver.get("https://mp.qutoutiao.net/publish-content/video")
    time.sleep(2)
    driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_mp4)
    # wait for upload ... (same loop as above)
    driver.find_element_by_xpath('//*[@placeholder="内容标题5-30字"]').clear()
    driver.find_element_by_xpath('//*[@placeholder="内容标题5-30字"]').send_keys(describe)
    driver.find_element_by_xpath('//textarea').clear()
    driver.find_element_by_xpath('//textarea').send_keys(describe)
    driver.find_element_by_xpath('//*[@placeholder="请选择分类"]').click()
    driver.find_element_by_xpath('//*[text()="电影"]').click()
    # add tags
    tag_input = driver.find_element_by_xpath('//*[@class="content-tag"]//input')
    for tag in ["视觉震撼", "搞笑", "电影"]:
        tag_input.send_keys(tag)
        time.sleep(2)
        tag_input.send_keys(Keys.ENTER)
    # add cover (same as above)
    # driver.find_element_by_xpath('//*[text()="发布"]').click()

publish_qutoutiao()

The script provides a practical example of using Selenium for web‑automation tasks related to content creation on a short‑video platform, making it useful for developers interested in automating repetitive UI workflows.

Pythonautomationvideo-uploadSeleniumWeb Automationqutoutiao
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.