|
|
|
@ -27,33 +27,36 @@ def login(page):
|
|
|
|
|
page.wait_for_url("https://ww1.colorlightcloud.com/home", timeout=60000) # 等待跳转到 home 页面
|
|
|
|
|
|
|
|
|
|
# 删除节目
|
|
|
|
|
def delProgram(page):
|
|
|
|
|
def delProgram(page,keyword):
|
|
|
|
|
# 点击“节目”
|
|
|
|
|
print("点击节目...")
|
|
|
|
|
program_library = page.get_by_text("节目").nth(0) # 通过 text 定位媒体库
|
|
|
|
|
program_library.click()
|
|
|
|
|
|
|
|
|
|
# 定位目标元素
|
|
|
|
|
element = page.locator("span.group-name").nth(0)
|
|
|
|
|
# 将鼠标移动到元素上
|
|
|
|
|
element.hover()
|
|
|
|
|
# 点击复选框
|
|
|
|
|
checkbox_span = page.locator("span.mat-checkbox-inner-container").nth(0)
|
|
|
|
|
checkbox_span.click()
|
|
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
# 点击删除按钮
|
|
|
|
|
print(page.locator("mat-icon:has-text('delete')").count())
|
|
|
|
|
|
|
|
|
|
delete_icon = page.locator("mat-icon:has-text('delete')").nth(0)
|
|
|
|
|
if delete_icon.is_visible():
|
|
|
|
|
delete_icon.click() # 点击该元素
|
|
|
|
|
# 定位并点击 <button> 元素
|
|
|
|
|
print("定位并点击确定按钮...")
|
|
|
|
|
confirm_button = page.locator("button:has-text('确定')")
|
|
|
|
|
if confirm_button.is_visible():
|
|
|
|
|
confirm_button.click() # 点击该元素
|
|
|
|
|
|
|
|
|
|
# 定位所有符合条件的 <div> 元素
|
|
|
|
|
divs = page.locator("div.content-title")
|
|
|
|
|
|
|
|
|
|
# 获取所有 <div> 元素中的文本内容
|
|
|
|
|
text_list = divs.evaluate_all("elements => elements.map(div => div.textContent.trim())")
|
|
|
|
|
|
|
|
|
|
# 遍历文本内容,找到包含 keyword 的元素
|
|
|
|
|
for index, text in enumerate(text_list):
|
|
|
|
|
if keyword in text:
|
|
|
|
|
print(f"Found element with text: {text}")
|
|
|
|
|
#点击
|
|
|
|
|
divs.nth(index).click()
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
# 点击删除按钮
|
|
|
|
|
print(page.locator("mat-icon:has-text('delete')").count())
|
|
|
|
|
delete_icon = page.locator("mat-icon:has-text('delete')").nth(0)
|
|
|
|
|
if delete_icon.is_visible():
|
|
|
|
|
delete_icon.click() # 点击该元素
|
|
|
|
|
# 定位并点击 <button> 元素
|
|
|
|
|
print("定位并点击确定按钮...")
|
|
|
|
|
confirm_button = page.locator("button:has-text('确定')")
|
|
|
|
|
if confirm_button.is_visible():
|
|
|
|
|
confirm_button.click() # 点击该元素
|
|
|
|
|
|
|
|
|
|
# 删除以前上传的素材
|
|
|
|
|
def delMaterial(page):
|
|
|
|
@ -208,8 +211,8 @@ def run(playwright: Playwright) -> None:
|
|
|
|
|
# 登录
|
|
|
|
|
login(page)
|
|
|
|
|
|
|
|
|
|
# 删除节目
|
|
|
|
|
delProgram(page)
|
|
|
|
|
# 只删除固定前缀的节目
|
|
|
|
|
delProgram(page,'Playlist')
|
|
|
|
|
|
|
|
|
|
# 删除素材
|
|
|
|
|
# delMaterial(page)
|
|
|
|
|