人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動態(tài)

Python+selenium 自動化快手短視頻發(fā)布的實現(xiàn)過程

發(fā)布日期:2021-12-26 08:38 | 文章來源:站長之家

第一章:效果展示

① 效果展示

② 素材展示

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

第二章:實現(xiàn)過程

① 調(diào)用已啟用的瀏覽器

通過調(diào)用已啟用的瀏覽器,可以實現(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()
# 進入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()
# 退出默認框架
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ā)布快手視頻
 '''
 
 # 進入創(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()
 # 進入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()
 # 退出默認框架
 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)
 
 # 人工進行檢查并發(fā)布
 # time.sleep(3)
 # # 點擊發(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)文章希望大家以后多多支持本站!

版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部