修复百世优惠券广告弹窗从未关闭的问题

- 新增 site_baishi.dismiss_baishi_popups():优惠券广告为全屏居中 Ant Design
  modal,关闭键是 .ant-modal-close(纯图标、无文字)。旧逻辑只识别 '关 闭'/
  '阅读完毕' 等文字按钮,广告关闭键无文字故从未被关闭;现直接点击
  .ant-modal-close 并做重试 + 消失校验,再处理阅读消息与配置检查弹窗。
- runtime._dismiss_initial_popups 百世分支改为调用该 helper。
- 调试模式临时开启 CDP 9223 端口,便于 Playwright CLI 技能挂载已登录页面
  读取内容(仅调试模式生效,服务模式不受影响)。
This commit is contained in:
Misaka
2026-07-19 19:12:53 +08:00
parent 8f79cbc5d7
commit 076557aacb
2 changed files with 51 additions and 24 deletions

View File

@@ -290,7 +290,10 @@ def launch_and_prepare(debug_mode=False, debug_target=""):
# 3. 启动 Playwright不用 with改 .start(),由 RuntimeContext.stop() 收尾)
pw = sync_playwright().start()
browser = pw.chromium.launch(headless=False)
# 调试模式临时开启 CDP 端口,便于外部 Playwright如 Playwright CLI 技能)
# 通过 connectOverCDP 挂载到已登录的页面读取内容。仅调试模式生效,不影响服务模式。
_launch_args = ["--remote-debugging-port=9223"] if debug_mode else []
browser = pw.chromium.launch(headless=False, args=_launch_args)
context = browser.new_context(viewport={"width": 1920, "height": 1080})
pages_map = {}
@@ -399,29 +402,10 @@ def _dismiss_initial_popups(pages_map):
try:
bs_page = pages_map["百世"]
bs_page.bring_to_front()
print(">> 正在处理【百世】阅读完毕与关闭按钮...")
for _ in range(4):
handled = False
try:
read_btns = bs_page.locator("button:has-text('阅读完毕')")
if read_btns.count() > 0:
for i in range(read_btns.count()):
if read_btns.nth(i).is_visible(timeout=500):
read_btns.nth(i).click()
handled = True
except Exception:
pass
try:
if bs_page.locator("button:has-text('关 闭')").is_visible(
timeout=500
):
bs_page.locator("button:has-text('关 闭')").click()
handled = True
except Exception:
pass
if not handled:
break
bs_page.wait_for_timeout(800)
print(">> 正在处理【百世】初始弹窗(阅读消息 / 配置检查 / 优惠券广告)...")
# 委托给 site_baishi 的专用清理:优惠券广告是全屏居中 modal
# 关闭键为 .ant-modal-close纯图标无文字必须点它才能真正关掉。
site_baishi.dismiss_baishi_popups(bs_page)
print(" ✅ 【百世】初始弹窗处理完成。")
except Exception:
pass