hub-gif 0d8e1962d7 refactor: 竞品报告迁入 pipeline,爬虫目录仅保留采集与兼容入口
competitor_report 子包与 jd_competitor_report 主模块移至 backend/pipeline;runner 与测试改为 from pipeline import jd_competitor_report;crawler_copy 下 jd_competitor_report 为转发 shim;jd_keyword_pipeline 文档更新。

Made-with: Cursor
2026-04-17 13:47:34 +08:00

43 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""配料列清洗:与 ``AI_crawler.normalize_ingredients_text_for_csv`` 等口径对齐。"""
from __future__ import annotations
import re
def _is_ingredient_url_blob(s: str) -> bool:
"""详情主图 URL 串(分号分隔)或单列以 http 开头。"""
t = (s or "").strip()
if not t:
return False
if t.startswith(("http://", "https://")):
return True
head = t[:400]
if ("https://" in head or "http://" in head) and (
";" in t or len(t) > 180 or t.count("http") >= 2
):
return True
return False
def _ingredients_from_product_attributes(attrs: str) -> str:
m = re.search(r"配料(?:表)?[:]\s*([^;]+)", attrs or "")
return m.group(1).strip() if m else ""
def _ingredients_single_line(s: str) -> str:
"""与 ``AI_crawler.normalize_ingredients_text_for_csv`` 一致:多行配料压成一行(行间 ````),便于表格/CSV。"""
t = (s or "").replace("\r\n", "\n").replace("\r", "\n").strip()
if not t:
return ""
lines = [ln.strip() for ln in t.split("\n") if ln.strip()]
if len(lines) <= 1:
return lines[0] if lines else ""
return "".join(lines)
__all__ = [
"_ingredients_from_product_attributes",
"_ingredients_single_line",
"_is_ingredient_url_blob",
]