feat(lps): 배송비 유형 분류 — 쿠팡 배송신호 파싱 + 네이버 배송비제외 명시
NormalizedProduct 에 shipping_type(rocket|rocket_merchant|free|paid|None) 추가. 쿠팡 파서: 로켓 뱃지(img src)로 유형, '무료배송'/'배송비 X원' 텍스트로 금액 판별 (상품명 '무료배송' 오탐은 이름 제거 후 매칭). 네이버 lprice 는 배송비 제외 상품가라 배송 필드 None — 카탈로그 '배송비포함 최저가'와 다른 이유를 docs/api.md 에 명시. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
313d882df4
commit
61bc719e28
5 files changed
+47
-1
No files matched your search
@@ -14,6 +14,8 @@ BASE = "https://www.coupang.com"
|
||||
|
||||
# '원' 바로 앞의 숫자만 가격으로 인식('(1개당 44,400원)'의 앞 '1' 오인 방지).
|
||||
_WON = re.compile(r"([\d,]+)\s*원")
|
||||
# 카드 내 명시 배송비(예: '배송비 3,000원').
|
||||
_SHIP_FEE = re.compile(r"배송비\s*([\d,]+)\s*원")
|
||||
|
||||
|
||||
def _sale_price(price_area) -> int | None:
|
||||
@@ -33,6 +35,30 @@ def _sale_price(price_area) -> int | None:
|
||||
return None
|
||||
|
||||
|
||||
def _shipping(card, name: str | None) -> tuple[int | None, str | None]:
|
||||
"""카드에서 (배송비, 배송유형) 추출.
|
||||
유형은 로켓 뱃지(img src)로, 금액은 '무료배송'/'배송비 X원' 텍스트로 판별한다.
|
||||
로켓 계열은 조건부 무료(와우/최소금액)라 명시 텍스트 없으면 배송비 None 유지.
|
||||
상품명에 '무료배송' 이 들어간 오탐을 막기 위해 이름 텍스트는 제거 후 매칭."""
|
||||
badge_type = None
|
||||
for img in card.css(S.rocket_badge):
|
||||
src = img.attributes.get("src") or ""
|
||||
badge_type = "rocket_merchant" if S.rocket_merchant_marker in src else "rocket"
|
||||
if badge_type == "rocket":
|
||||
break # 로켓배송 뱃지가 가장 강한 신호
|
||||
|
||||
text = card.text(separator=" ") or ""
|
||||
if name:
|
||||
text = text.replace(name, " ")
|
||||
|
||||
if "무료배송" in text:
|
||||
return 0, badge_type or "free"
|
||||
m = _SHIP_FEE.search(text)
|
||||
if m:
|
||||
return int(m.group(1).replace(",", "")), badge_type or "paid"
|
||||
return None, badge_type
|
||||
|
||||
|
||||
def parse_search_html(html: str, source: str = "coupang") -> list[NormalizedProduct]:
|
||||
tree = HTMLParser(html)
|
||||
products: list[NormalizedProduct] = []
|
||||
@@ -57,6 +83,8 @@ def parse_search_html(html: str, source: str = "coupang") -> list[NormalizedProd
|
||||
href = a.attributes.get("href") if a else None
|
||||
detail_url = (BASE + href) if href and href.startswith("/") else href
|
||||
|
||||
shipping_fee, shipping_type = _shipping(card, name)
|
||||
|
||||
products.append(
|
||||
NormalizedProduct(
|
||||
source=source,
|
||||
@@ -66,6 +94,8 @@ def parse_search_html(html: str, source: str = "coupang") -> list[NormalizedProd
|
||||
detail_url=detail_url,
|
||||
mall_name="쿠팡",
|
||||
external_id=card.attributes.get(S.data_id_attr),
|
||||
shipping_fee=shipping_fee,
|
||||
shipping_type=shipping_type,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user