fix: 兼容带数量的规格面板标题 (#137)
This commit is contained in:
@@ -432,11 +432,42 @@ def _dimension_key(name: str, used: set[str]) -> str:
|
||||
|
||||
def _is_dimension_heading(label: str) -> bool:
|
||||
compact = label.replace(" ", "")
|
||||
# 新版页面会把可选数量写进标题,例如“颜色 (6)”或“颜色(6)”。
|
||||
# 数量不是规格名称的一部分,只在判断标题类型时去掉,最终展示仍保留原文。
|
||||
compact = re.sub(r"[((]\d+[))]$", "", compact)
|
||||
return compact in _DIMENSION_NAMES or compact.endswith(
|
||||
("分类", "规格", "尺寸", "尺码", "颜色", "型号", "款式", "容量", "类型", "版本", "口味")
|
||||
)
|
||||
|
||||
|
||||
def _is_spec_panel_open(xml_data: str | bytes) -> bool:
|
||||
"""判断规格面板是否已经出现,不要求当前视口已露出规格选项。"""
|
||||
|
||||
root = _parse_xml(xml_data)
|
||||
labels = _all_labels(root)
|
||||
_raise_special_page(labels)
|
||||
has_scrollable_region = any(
|
||||
node.get("scrollable") == "true"
|
||||
and _parse_bounds(node.get("bounds", "")) is not None
|
||||
for node in root.iter("node")
|
||||
)
|
||||
if not has_scrollable_region:
|
||||
return False
|
||||
|
||||
compact_labels = [label.replace(" ", "") for label in labels]
|
||||
has_selection_summary = any(
|
||||
label.startswith(("请选择", "已选"))
|
||||
and any(word in label for word in ("颜色", "尺码", "规格", "款式"))
|
||||
for label in compact_labels
|
||||
)
|
||||
has_submit_hint = any(
|
||||
"提交订单" in label
|
||||
and any(word in label for word in ("选择", "颜色", "尺码", "规格"))
|
||||
for label in compact_labels
|
||||
)
|
||||
return has_selection_summary or has_submit_hint
|
||||
|
||||
|
||||
def _top_level_clickable_options(
|
||||
container: ET.Element,
|
||||
parents: Mapping[ET.Element, ET.Element],
|
||||
@@ -1027,7 +1058,7 @@ class PddCollectService:
|
||||
if exc.code != "PDD_DATA_SPEC_INCOMPLETE":
|
||||
raise
|
||||
else:
|
||||
if snapshot.dimensions:
|
||||
if snapshot.dimensions or _is_spec_panel_open(xml_data):
|
||||
return snapshot
|
||||
self._sleep(0.25)
|
||||
raise PddCollectError(
|
||||
|
||||
Reference in New Issue
Block a user