feat(lps): 최저가 오퍼의 신뢰 신호(평점·리뷰) 수집 — 네이버·쿠팡 공통

'가장 싼 값'과 '실제로 살 수 있는 가장 싼 값'은 다르다. 리뷰·평점이 전혀 없는 오퍼는
재고 없는 미끼가격일 수 있고, 그걸 최저가로 보고하면 사용자는 그 가격에 살 수 없다 —
조금 비싼 정답보다 나쁘다. 판단 근거를 수집해 둔다.

- NormalizedProduct.rating / review_count 추가. 두 소스 모두 카드에 노출하는 값만 담아
  교차 비교가 되게 했다. **없으면 None 유지** — '리뷰 0개'와 '리뷰 정보 없음'은 다른 뜻이다
- 네이버: product_grade 의 <strong>평점</strong><em>리뷰수</em>. 텍스트를 통째로 정규식
  돌리면 '평점4.7473' 이 4.74/73 인지 4.7/473 인지 못 가르므로 노드로 분리해 읽는다.
  '1.7만' 같은 축약은 parse_ko_count 로 푼다(그대로 int() 하면 1 이 된다)
- 쿠팡: 별점은 채워진 별 개수가 아니라 컨테이너 aria-label 에, 리뷰 수는 괄호 텍스트에 있다
- price_history.final_rating/final_review_count 추가(+마이그레이션) → "리뷰 0인 최저가가
  몇 %인가"를 SQL 로 물을 수 있다. NULL 과 0 을 구분해야 해서 기본값을 두지 않았다

정렬 점검(사용자 제기): 두 소스 다 정렬 파라미터 없이 **랭킹/추천순**이다(픽스처 가격이
오름차순이 아님으로 확인). 가격순(sort=price_asc)은 차단 없이 동작하고 실측상 더 싼 후보를
찾지만(15,400→10,900), 리뷰·평점 없는 유령상품을 위로 끌어올려 미채택 — 추천순 유지.
신뢰 신호가 쌓이면 "리뷰 N 이상" 가드를 걸고 가격순을 켜는 선택지가 열린다.

e2e: TR-1/TR-2 최저가에 평점 4.89·리뷰 7,314/102,000 이 함께 기록됨. 테스트 5건 추가, 228 passed.
This commit is contained in:
민헌 committed 2026-08-05 14:00:12 +09:00
1 parent 5c9567919f
commit 6c7ff5af51
13 files changed
+142 -4

No files matched your search

+6
View File
@@ -27,6 +27,12 @@ class NormalizedProduct(BaseModel):
shipping_type: Optional[str] = Field(None, description="배송 유형: free(명시 무료)|paid(유료)|rocket(로켓배송, 조건부 무료)|rocket_merchant(판매자로켓)|None(미확인). 네이버는 lprice 가 배송비 제외 상품가라 항상 None")
mall_name: Optional[str] = Field(None, description="판매몰/스토어명")
external_id: Optional[str] = Field(None, description="소스 내 상품 식별자")
# ── 신뢰 신호 ──────────────────────────────────────────────────────
# 최저가는 '가장 싼 값'이 아니라 '실제로 살 수 있는 가장 싼 값'이어야 한다. 리뷰·평점이
# 전혀 없는 오퍼는 재고 없는 미끼가격일 수 있어, 그걸 최저가로 보고하면 사용자는 그 가격에
# 살 수 없다. 두 소스 모두 카드에 노출하는 값만 담는다(교차 비교가 되어야 하므로).
rating: Optional[float] = Field(None, description="평점(5점 만점). 없으면 None=신규/미검증 오퍼 신호")
review_count: Optional[int] = Field(None, description="리뷰 수. 0/None 이면 거래 이력이 없다는 뜻")
class AdapterHealth(BaseModel):
+20
View File
@@ -16,6 +16,25 @@ BASE = "https://www.coupang.com"
_WON = re.compile(r"([\d,]+)\s*원")
# 카드 내 명시 배송비(예: '배송비 3,000원').
_SHIP_FEE = re.compile(r"배송비\s*([\d,]+)\s*원")
# 리뷰 수는 별점 옆 괄호에 들어온다 — "(41,448)".
_REVIEW = re.compile(r"\(([\d,]+)\)")
def _trust(card) -> dict:
"""평점·리뷰 수. 리뷰가 없으면 이 노드 자체가 없다 — None 을 유지해 '미검증 오퍼'로 남긴다
(0 으로 채우면 '리뷰 0개'와 '리뷰 정보 없음'이 구분되지 않는다)."""
area = card.css_first(S.rating_area)
if area is None:
return {"rating": None, "review_count": None}
rating = None
holder = area.css_first(f"[{S.rating_value_attr}]")
if holder is not None:
try:
rating = float(holder.attributes.get(S.rating_value_attr) or "")
except ValueError:
rating = None
m = _REVIEW.search(area.text() or "")
return {"rating": rating, "review_count": int(m.group(1).replace(",", "")) if m else None}
def _sale_price(price_area) -> int | None:
@@ -96,6 +115,7 @@ def parse_search_html(html: str, source: str = "coupang") -> list[NormalizedProd
external_id=card.attributes.get(S.data_id_attr),
shipping_fee=shipping_fee,
shipping_type=shipping_type,
**_trust(card),
)
)
+4
View File
@@ -20,6 +20,10 @@ class CoupangSelectors:
# 배송 뱃지: 로고 이미지 src 로 판별(배송 텍스트는 해시 없는 인라인 스타일 span 이라 텍스트 매칭).
rocket_badge: str = "img[src*=rocket]"
rocket_merchant_marker: str = "rocket_merchant" # src 에 포함 시 판매자로켓, 그 외 rocket* 는 로켓배송
# 신뢰 신호 — 별점은 채워진 별 개수가 아니라 **컨테이너의 aria-label**(예: "5")에 들어 있고,
# 리뷰 수는 그 옆 괄호 텍스트("(41,448)")다.
rating_area: str = "[class*=ProductRating_productRating]"
rating_value_attr: str = "aria-label"
SELECTORS = CoupangSelectors()
+19
View File
@@ -25,6 +25,7 @@ from selectolax.parser import HTMLParser
from common.logger import LOG
from services.search.contract import NormalizedProduct
from services.search.util import parse_ko_count
from services.search.naver_shop.selectors import SELECTORS as S
_NUM = re.compile(r"([\d,]{3,})\s*원")
@@ -70,6 +71,7 @@ def parse_search_html(html: str, source: str = "naver") -> list[NormalizedProduc
detail_url=_href(card),
shipping_fee=fee,
shipping_type=ship_type,
**_trust(card),
))
if out or any(skipped.values()):
@@ -132,6 +134,23 @@ def _shipping(card) -> tuple[int | None, str | None]:
return (won, "paid") if won else (None, None)
def _trust(card) -> dict:
"""평점·리뷰 수. 없으면 None — '신규/미검증 오퍼'라는 정보 자체가 의미 있으므로 0 으로 채우지 않는다."""
node = card.css_first(S.grade)
if node is None:
return {"rating": None, "review_count": None}
rating_node = node.css_first(S.grade_rating)
review_node = node.css_first(S.grade_review)
rating = None
if rating_node is not None:
try:
rating = float(rating_node.text().strip())
except ValueError:
rating = None
return {"rating": rating,
"review_count": parse_ko_count(review_node.text()) if review_node is not None else None}
def _href(card) -> str | None:
node = card.css_first(S.link)
href = node.attributes.get("href") if node else None
@@ -28,6 +28,11 @@ class Selectors:
coupon_price: str = "[class*=product_discount_price]" # 쿠폰할인가(조건부) — price 로 쓰지 않는다
delivery_fee: str = "[class*=product_delivery_fee]" # "배송비무료" | "배송비3,000원"
mall: str = "[class*=product_mall]"
# 신뢰 신호 — 평점/리뷰는 같은 노드 안에 <strong>4.88</strong><em>1.7만</em> 로 들어온다.
# 텍스트를 통째로 정규식 돌리면 '평점4.7473' 처럼 붙어 나와 4.74/73 인지 4.7/473 인지 못 가른다.
grade: str = "[class*=product_grade]"
grade_rating: str = "strong"
grade_review: str = "em"
link: str = "[class*=product_btn_link]"
# 광고 배지. adProduct 계열에만 존재하지만, 유기 카드에 광고가 섞이는 경우까지 방어한다.
+19
View File
@@ -55,3 +55,22 @@ def shipping_from_text(text: str, name: str | None = None) -> tuple[int | None,
if m:
return int(m.group(1).replace(",", "")), "paid"
return None, None
def parse_ko_count(text: str) -> int | None:
"""'1.7만'→17000 · '3,705'→3705 · '1.2천'→1200 · ''→None.
네이버는 리뷰·구매 수를 만/천 단위로 줄여 쓴다. 그대로 int() 하면 1.7만이 1이 된다.
"""
if not text:
return None
t = text.strip().replace(",", "")
m = re.match(r"^([\d.]+)\s*([만천])?$", t)
if not m:
return None
try:
n = float(m.group(1))
except ValueError:
return None
unit = {"만": 10000, "천": 1000}.get(m.group(2) or "", 1)
return int(n * unit)