Python+selenium 自動化快手短視頻發(fā)布的實(shí)現(xiàn)過程
第一章:效果展示
① 效果展示

② 素材展示
一個為視頻,另一個為像素大小不小于視頻的封面。

第二章:實(shí)現(xiàn)過程
① 調(diào)用已啟用的瀏覽器
通過調(diào)用已啟用的瀏覽器,可以實(shí)現(xiàn)直接跳過每次的登錄過程。
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress", "127.0.0.1:5003")
driver = webdriver.Chrome(options = options)
② 上傳視頻和圖片
上傳功能的使用方法可以查看:
# 上傳本地視頻
driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_mp4)
# 添加封面
time.sleep(2)
driver.find_element_by_xpath('//button//*[contains(text(),"編輯封面")]').click()
# 進(jìn)入iframe框架
driver.switch_to.frame(driver.find_element_by_xpath('//iframe'))
time.sleep(1)
driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_cover)
time.sleep(10)
driver.find_element_by_xpath('//button[text()="確定"]').click()
# 退出默認(rèn)框架
driver.switch_to_default_content()
③ 完整源碼展示
import selenium
from selenium import webdriver
import pathlib
import time
from selenium.webdriver.common.keys import Keys
# 基本信息
# 視頻存放路徑
catalog_mp4 = r"C:\Users\Administrator\Desktop\視頻發(fā)布"
# 視頻描述
describe = "裸眼3D看蜘蛛俠 #搞笑 #電影 #視覺震撼"
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_kuaishou():
'''
作用:發(fā)布快手視頻
'''
# 進(jìn)入創(chuàng)作者頁面,并上傳視頻
driver.get("https://cp.kuaishou.com/article/publish/video?origin=www.kuaishou.com")
time.sleep(3)
driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_mp4)
# 等待視頻上傳完成
while True:
time.sleep(3)
try:
driver.find_element_by_xpath('//*[contains(text(),"上傳成功")]')
break;
except Exception as e:
print("視頻還在上傳中···")
print("視頻已上傳完成!")
# 添加封面
time.sleep(2)
driver.find_element_by_xpath('//button//*[contains(text(),"編輯封面")]').click()
# 進(jìn)入iframe框架
driver.switch_to.frame(driver.find_element_by_xpath('//iframe'))
time.sleep(1)
driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_cover)
time.sleep(10)
driver.find_element_by_xpath('//button[text()="確定"]').click()
# 退出默認(rèn)框架
driver.switch_to_default_content()
# 切換常規(guī)視頻
time.sleep(2)
driver.find_element_by_xpath('//*[contains(text(),"去上傳常規(guī)視頻")]').click()
time.sleep(3)
# 輸入視頻描述
driver.find_element_by_xpath('//*[@placeholder="添加合適的話題和描述,作品能獲得更多推薦~"]').send_keys(describe)
# 選擇分類
driver.find_element_by_xpath('//*[@placeholder="請選擇"]').click()
time.sleep(2)
driver.find_element_by_xpath('//*[text()="影視"]').click()
time.sleep(1)
# 人工進(jìn)行檢查并發(fā)布
# time.sleep(3)
# # 點(diǎn)擊發(fā)布
# driver.find_element_by_xpath('//*[text()="發(fā)布"]').click()
# 開始執(zhí)行視頻發(fā)布
publish_kuaishou()
到此這篇關(guān)于Python+selenium 自動化快手短視頻發(fā)布的文章就介紹到這了,更多相關(guān)Python selenium 自動化 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- python網(wǎng)絡(luò)爬蟲selenium打開多窗口與切換頁面的實(shí)現(xiàn)
- python實(shí)現(xiàn)selenium網(wǎng)絡(luò)爬蟲的方法小結(jié)
- python網(wǎng)絡(luò)爬蟲 Scrapy中selenium用法詳解
- Python+selenium實(shí)現(xiàn)趣頭條的視頻自動上傳與發(fā)布
- Python + selenium 自動化測試框架詳解
- python自動化測試selenium屏幕截圖示例
- Python編程使用Selenium模擬淘寶登錄實(shí)現(xiàn)過程
- Python結(jié)合Selenium簡單實(shí)現(xiàn)Web自動化測試
- 利用Python+Selenium破解春秋航空網(wǎng)滑塊驗(yàn)證碼的實(shí)戰(zhàn)過程
- python網(wǎng)絡(luò)爬蟲基于selenium爬取斗魚直播信息
相關(guān)文章
K-近鄰算法的python實(shí)現(xiàn)代碼分享
這篇文章主要介紹了K-近鄰算法的python實(shí)現(xiàn)代碼分享,具有一定借鑒價值,需要的朋友可以參考下。2017-12-12
Python 讀取千萬級數(shù)據(jù)自動寫入 MySQL 數(shù)據(jù)庫
這篇文章主要介紹了Python 讀取千萬級數(shù)據(jù)自動寫入 MySQL 數(shù)據(jù)庫,本篇文章會給大家系統(tǒng)的分享千萬級數(shù)據(jù)如何寫入到 mysql,分為兩個場景,兩種方式2022-06-06
Python matplotlib 畫圖窗口顯示到gui或者控制臺的實(shí)例
今天小編就為大家分享一篇Python matplotlib 畫圖窗口顯示到gui或者控制臺的實(shí)例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-05-05
Macbook air m1安裝python/anaconda全過程(圖文)
這篇文章主要介紹了Macbook air m1安裝python/anaconda全過程(圖文),文中通過圖文介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03
django drf框架中的user驗(yàn)證以及JWT拓展的介紹
這篇文章主要介紹了django drf框架中的user驗(yàn)證以及JWT拓展的介紹,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Python 實(shí)現(xiàn)敏感目錄掃描的示例代碼
這篇文章主要介紹了Python 實(shí)現(xiàn)敏感目錄掃描的示例代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05
Python requests模塊session代碼實(shí)例
這篇文章主要介紹了Python requests模塊session代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-04-04

