import time from playwright.sync_api import Playwright, sync_playwright # 登录 def login(page): # 打开登录页面 print("打开登录页面...") page.goto("https://ww1.colorlightcloud.com/login", wait_until="domcontentloaded") # 等待 DOM 加载完成 # 输入用户名 print("输入用户名...") username_input = page.locator("#mat-input-0") # 通过 id 定位用户名输入框 username_input.fill("Ylt5786") # 输入密码 print("输入密码...") password_input = page.locator("input[type='password']") # 根据实际元素定位密码输入框 password_input.fill("DJCtjy064") # 点击登录按钮 print("点击登录按钮...") login_button = page.locator("button.color-login-btn") # 通过 class 定位登录按钮 login_button.click() # 等待登录成功 print("等待登录成功...") page.wait_for_url("https://ww1.colorlightcloud.com/home", timeout=60000) # 等待跳转到 home 页面 # 删除节目 def delProgram(page,keyword): # 点击“节目” print("点击节目...") program_library = page.get_by_text("节目").nth(0) # 通过 text 定位媒体库 program_library.click() time.sleep(1) # 定位所有符合条件的
元素 divs = page.locator("div.content-title") # 获取所有
元素中的文本内容 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() # 点击该元素 # 定位并点击