fix: 抓取元素回填垃圾选择器——无属性元素生成 //*[N](匹配任意节点点不到),改为 invalid 标记前端提示不可选;结构路径跳过无 class 层消除 //*[N] 前缀污染;模块拆分遗漏修复(get_all_worker_status/list_installed_apps 致 summary/设备已装应用 500)
This commit is contained in:
+17
-5
@@ -190,9 +190,14 @@ def _extract(root, out):
|
||||
desc = props.get("content-desc", "")
|
||||
cls = props.get("class", "")
|
||||
tag = cls.split(".")[-1] if cls else "*"
|
||||
# 始终带同 class 兄弟序号(含 [1]),结构路径才精确无歧义
|
||||
seg = f"{tag}[{tag_index}]"
|
||||
own_tag_path = f"{tag_path}/{seg}" if tag_path else seg
|
||||
# 始终带同 class 兄弟序号(含 [1]),结构路径才精确无歧义;
|
||||
# class 为空的层(tag=*)不参与结构路径,避免 //*[N] 前缀污染导致选择器定位到任意节点
|
||||
if tag != "*":
|
||||
seg = f"{tag}[{tag_index}]"
|
||||
own_tag_path = f"{tag_path}/{seg}" if tag_path else seg
|
||||
else:
|
||||
seg = ""
|
||||
own_tag_path = tag_path
|
||||
|
||||
# ---- 推荐选择器:唯一属性 > 锚点祖先限定 > 全结构路径 ----
|
||||
if rid:
|
||||
@@ -206,8 +211,15 @@ def _extract(root, out):
|
||||
suggested = {"type": "xpath", "value": val}
|
||||
child_ctx = val
|
||||
else:
|
||||
# 无唯一属性且无锚点祖先:用从根开始的结构路径(脆弱,标记 broad 让前端提示)
|
||||
suggested = {"type": "xpath", "value": f"//{own_tag_path}", "broad": True}
|
||||
if tag == "*":
|
||||
# class 也为空的元素:结构路径 //*[N] 无意义(匹配到文档任意节点),
|
||||
# 标记 invalid,前端提示不可选,避免回填垃圾选择器导致"点击不到"
|
||||
suggested = {"type": "xpath", "value": "",
|
||||
"invalid": True,
|
||||
"reason": "该元素无可用属性(id/文本/class),无法生成可靠选择器"}
|
||||
else:
|
||||
# 无唯一属性且无锚点祖先:用从根开始的结构路径(脆弱,标记 broad 让前端提示)
|
||||
suggested = {"type": "xpath", "value": f"//{own_tag_path}", "broad": True}
|
||||
child_ctx = None
|
||||
|
||||
out.append({
|
||||
|
||||
Reference in New Issue
Block a user