導讀:
本系列依次介紹目前主流的短視訊平台(抖音、快手、B站、微視、小紅書、好看視訊、西瓜視訊、視訊号、搜狐視訊等)的短視訊自動釋出,希望幫助大家更友善、高效的來進行自媒體的創作與管理。
【本文介紹的是微視的短視訊自動釋出。】
- - - -系列文章- - - -
Python+selenium 自媒體自動化 - 實作自動投稿、自動釋出哔哩哔哩 B 站短視訊執行個體示範Python+selenium 自動化 - 微視短視訊釋出
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLiYWan5SNjNmZ5UGN3YTNlZWYyYjYlhjZ0UTM3gTYwImYwkTM18CX5d2bs92Yl1iclB3bsVmdlR2LcNWaw9CXt92Yu4GZjlGbh5yYjV3Lc9CX6MHc0RHaiojIsJye.gif)
一個為視訊,另一個為像素大小不小于視訊的封面。
通過調用已啟用的浏覽器,可以實作直接跳過每次的登入過程。
使用方法可以檢視:
Python+selenium 自動化 - 操作已啟用的 chrome 浏覽器執行個體示範,chrome 啟用調試端口方法from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress", "127.0.0.1:5003")
driver = webdriver.Chrome(options = options)
上傳功能的使用方法可以檢視:
Python+selenium 自動化 - 實作自動導入、上傳外部檔案執行個體示範# 上傳本地視訊
driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_mp4)
# 上傳封面
driver.find_element_by_xpath('//div[text()="圖檔上傳"]').click()
time.sleep(1)
driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_cover)
import selenium
from selenium import webdriver
import pathlib
import time
from selenium.webdriver.common.keys import Keys
# 基本資訊
# 視訊存放路徑
catalog_mp4 = r"C:\Users\Administrator\Desktop\視訊釋出"
# 視訊描述
describe = "AI·熱帶亞馬遜·奇幻星空 #視覺震撼 #旅行 #AI #星空 #大自然"
time.sleep(10)
options = webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress", "127.0.0.1:5003")
driver = webdriver.Chrome(options = options)
path = pathlib.Path(catalog_mp4)
# 視訊位址擷取
path_mp4 = ""
for i in path.iterdir():
if(".mp4" in str(i)):
path_mp4 = str(i);
break;
if(path_mp4 != ""):
print("檢查到視訊路徑:" + path_mp4)
else:
print("未檢查到視訊路徑,程式終止!")
exit()
# 封面位址擷取
path_cover = ""
for i in path.iterdir():
if(".png" in str(i) or ".jpg" in str(i)):
path_cover = str(i);
break;
if(path_cover != ""):
print("檢查到封面路徑:" + path_cover)
else:
print("未檢查到封面路徑,程式終止!")
exit()
def publish_weishi():
'''
作用:釋出微視視訊
'''
# 進入微視創作者頁面,并上傳視訊
driver.get("https://media.weishi.qq.com/")
time.sleep(2)
driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_mp4)
# 等待視訊上傳完成
while True:
time.sleep(3)
try:
driver.find_element_by_xpath('//video')
break;
except Exception as e:
print("視訊還在上傳中···")
print("視訊已上傳完成!")
# 添加封面
driver.find_element_by_xpath('//div[text()="設定封面"]').click()
time.sleep(1)
# driver.find_element_by_xpath('//div[text()="圖檔上傳"]').click()
# time.sleep(1)
# driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_cover)
time.sleep(1)
driver.find_element_by_xpath('//div[text()="确定"]').click()
time.sleep(1)
# 輸入視訊描述
driver.find_element_by_xpath('//textarea').send_keys(describe)
# 人工進行檢查并釋出
time.sleep(3)
# 點選釋出
driver.find_element_by_xpath('//span[text()="發 布"]').click()
# 開始執行微視視訊釋出
publish_weishi()
喜歡的點個贊❤吧!