Fix Baishi scan-query selector ambiguity and add password guard
- Scope the 扫描综合查询 click to .nav-level2-wrapper to avoid collision with the right-side tab of the same name - Warn when config.yaml has no baishi.password before attempting export Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,8 +16,14 @@ def baishi_download_undelivered_data(page):
|
|||||||
try:
|
try:
|
||||||
# 1. 导航与页面加载
|
# 1. 导航与页面加载
|
||||||
print(">> 正在进入【扫描综合查询】界面...")
|
print(">> 正在进入【扫描综合查询】界面...")
|
||||||
|
# 打开基础服务菜单面板
|
||||||
page.locator("div.nav-level1", has_text="基础服务").click()
|
page.locator("div.nav-level1", has_text="基础服务").click()
|
||||||
page.locator("li a", has_text="扫描综合查询").click()
|
|
||||||
|
# 【重要修复】:通过限制在菜单面板(nav-level2-wrapper)内查找,
|
||||||
|
# 完美避开页面右侧同名 Tab 标签页的干扰
|
||||||
|
page.locator(".nav-level2-wrapper").locator(
|
||||||
|
"a", has_text="扫描综合查询"
|
||||||
|
).click()
|
||||||
|
|
||||||
# 验证表格主界面加载完毕
|
# 验证表格主界面加载完毕
|
||||||
page.get_by_role("tab", name="实时扫描率").wait_for(state="visible")
|
page.get_by_role("tab", name="实时扫描率").wait_for(state="visible")
|
||||||
@@ -49,6 +55,11 @@ def baishi_download_undelivered_data(page):
|
|||||||
with open("config.yaml", "r", encoding="utf-8") as f:
|
with open("config.yaml", "r", encoding="utf-8") as f:
|
||||||
config = yaml.safe_load(f)
|
config = yaml.safe_load(f)
|
||||||
password = config.get("baishi", {}).get("password", "")
|
password = config.get("baishi", {}).get("password", "")
|
||||||
|
|
||||||
|
if not password:
|
||||||
|
print(
|
||||||
|
" ⚠️ 警告:在 config.yaml 中未找到百世的登录密码,可能导致导出失败。"
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" ⚠️ 读取 config.yaml 失败,请确保文件存在且格式正确: {e}")
|
print(f" ⚠️ 读取 config.yaml 失败,请确保文件存在且格式正确: {e}")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user