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 = "裸眼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_xigua():
'''
作用:发布西瓜短视频
'''
# 进入创作者页面,并上传视频
driver.get("https://studio.ixigua.com/upload?from=post_article")
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('//*[text()="上传成功"]')
break;
except Exception as e:
print("视频还在上传中···")
print("视频已上传完成!")
# 输入标题
time.sleep(2)
driver.find_element_by_xpath('//*[@data-editor="title"]/*').send_keys(describe)
# 添加封面
time.sleep(1)
driver.find_element_by_xpath('//*[text()="上传封面"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[text()="本地上传"]').click()
time.sleep(1)
driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_cover)
time.sleep(1)
# 等待确定按钮可点击
while True:
time.sleep(3)
try:
driver.find_element_by_xpath('//*[text()="确定" and @style="opacity: 1;"]').click()
break;
except Exception as e:
print("按钮不可点击···")
time.sleep(1)
driver.find_element_by_xpath('//*[contains(text(),"完成后无法继续编辑")]/..//*[text()="确定"]').click()
# 选择分类
time.sleep(3)
driver.find_element_by_xpath('//*[text()="原创"]').click()
time.sleep(2)
# 人工进行检查并发布
# time.sleep(3)
# # 点击发布
# driver.find_element_by_xpath('//*[text()="发布"]').click()
# 开始执行视频发布
publish_xigua()
网友评论