main
HuangHai 5 months ago
parent d57c881537
commit 094795af4c

@ -2,7 +2,7 @@ import time
from playwright.sync_api import Playwright, sync_playwright
# 隐藏浏览器
#HEADLESS = True
# HEADLESS = True
HEADLESS = False
# 素材的固定文件夹名称
MATERIAL_FOLDER_NAME = '播报充电情况'
@ -211,8 +211,9 @@ def changeJieMu(page):
program_library.click()
time.sleep(1)
# 排程
def paiCheng(page):
def paiCheng(page, keyword):
pc_library = page.get_by_text("排程").nth(0)
pc_library.click()
@ -251,9 +252,9 @@ def paiCheng(page):
# 获取所有 <span> 元素的文本内容
text_list = spans.evaluate_all("elements => elements.map(span => span.textContent.trim())")
# 找到第一个以 "Test" 开头的 <span> 元素
# 找到第一个以 keyword 开头的 <span> 元素
for index, text in enumerate(text_list):
if text.startswith("Test"):
if text.startswith(keyword):
print(f"Found first span with text: {text}")
# 获取元素的句柄并强制点击
span_handle = spans.nth(index).element_handle()
@ -267,7 +268,38 @@ def paiCheng(page):
span_handle.evaluate("element => element.click()")
break
time.sleep(1)
# 定位目标 <input> 元素
input_element = page.locator("input#mat-input-3") # 通过 id 定位
input_element.click()
# 定位目标 <input> 元素
hour_input = page.locator("input.owl-dt-timer-input").nth(0) # 第一个输入框(小时)
minute_input = page.locator("input.owl-dt-timer-input").nth(1) # 第二个输入框(分钟)
second_input = page.locator("input.owl-dt-timer-input").nth(2) # 第三个输入框(秒)
# 输入时间
hour_input.fill("12") # 输入小时
minute_input.fill("00") # 输入分钟
second_input.fill("00") # 输入秒
time.sleep(1)
# 定位 <button> 元素
set_button = page.locator("button.owl-dt-control-button", has_text="Set")
set_button.click()
# 定位目标 <input> 元素
time_input = page.locator("input#mat-input-4") # 通过 id 定位
# 点击 <input> 元素
time_input.click()
# 定位目标 <input> 元素
hour_input = page.locator("input.owl-dt-timer-input").nth(3) # 第一个输入框(小时)
minute_input = page.locator("input.owl-dt-timer-input").nth(4) # 第二个输入框(分钟)
second_input = page.locator("input.owl-dt-timer-input").nth(5) # 第三个输入框(秒)
# 输入时间
hour_input.fill("13") # 输入小时
minute_input.fill("01") # 输入分钟
second_input.fill("00") # 输入秒
def run(playwright: Playwright) -> None:
# 启动浏览器,禁用无头模式
@ -280,22 +312,22 @@ def run(playwright: Playwright) -> None:
login(page)
# 只删除固定前缀的节目
#delProgram(page, PREFIX_NAME)
# delProgram(page, PREFIX_NAME)
# 删除素材
#delMaterial(page)
# delMaterial(page)
# 上传文件
#uploadVideo(page, VIDEO_PATH)
# uploadVideo(page, VIDEO_PATH)
# 发布节目
#publish(page)
# publish(page)
# 切换到节目
#changeJieMu(page)
# changeJieMu(page)
# 排程
paiCheng(page)
paiCheng(page, PREFIX_NAME)
time.sleep(100)

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 B

Loading…
Cancel
Save