fix(lps): 쿠팡 차단 감지 다종화 — Edge Deny·권한제한·짧은HTML 폴백

기존엔 Akamai JS 챌린지 마커만 감지해, Edge Access Denied(errors.edgesuite.net)와
'사용권한이 제한된' 권한제한 페이지가 blocked=False 로 오판됐다. 그 결과 IP 회전·
bot_detection 기록이 누락되고 같은 IP 로 재시도만 반복하다 DEAD 로 빠졌다.

- 마커 3계열로 확장(Akamai / Edge Deny / 권한제한)
- 짧은 HTML 폴백(_MIN_RESULT_HTML): 0건인데 <10KB 면 미지의 차단으로 간주
  (정상 '검색결과 없음'은 전체 chrome 포함이라 큼)
- 감지를 순수 함수 detect_block(html, product_count) 로 분리 — 단위 테스트 6종

검증: 신라면 '사용권한이 제한된'(3383B) 감지 → IP 회전 → 새 IP 59건 복구.
파서 배송 분류 테스트도 함께 추가(shared fixture).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
민헌andClaude Fable 5 committed 2026-07-09 13:59:43 +09:00
1 parent 61bc719e28
commit 8460a5d833
2 files changed
+93 -3

No files matched your search

+26 -3
View File
@@ -21,11 +21,34 @@ from services.search.coupang.parser import parse_search_html
from services.search.coupang.selectors import SELECTORS
_SEARCH_URL = "https://www.coupang.com/np/search?q={q}&channel=user&listSize={n}"
_BLOCK_MARKERS = ("sec-if-cpt-container", "Powered and protected", "/akam/")
# 쿠팡 차단은 여러 flavor 다 — 하나만 잡으면 나머지는 blocked=False 로 오판(→회전·기록 누락).
# 1) Akamai JS 챌린지: sec-if-cpt-container / /akam/ / Powered and protected
# 2) Edge Access Denied(수백 B): errors.edgesuite.net / You don't have permission to access
# 3) 권한 제한 페이지: '사용권한이 제한된' / '쿠팡을 찾아주신 고객님'
_BLOCK_MARKERS = (
"sec-if-cpt-container", "Powered and protected", "/akam/",
"errors.edgesuite.net", "You don't have permission to access",
"사용권한이 제한된", "쿠팡을 찾아주신 고객님",
)
# 정상 검색결과·'검색결과 없음' 페이지는 전체 chrome 포함이라 수십 KB+ 다.
# 이보다 짧은데 0건이면 미지의 차단/에러 페이지로 간주(마커 없어도 회전 트리거).
_MIN_RESULT_HTML = 10000
# 대역폭 절감: 이미지/미디어/폰트/CSS 는 상품 데이터·Akamai(JS) 에 불필요 → 차단(프록시 per-GB 비용↓).
_BLOCKED_RESOURCES = {"image", "media", "font", "stylesheet"}
def detect_block(html: str, product_count: int) -> str | None:
"""0건 응답의 차단 여부 판정(순수 함수 — 브라우저 무관, 단위 테스트 가능).
반환: 차단 마커 문자열(차단) 또는 None(정상 빈결과). 상품이 있으면 항상 None.
알려진 마커 우선, 없으면 비정상적으로 짧은 HTML 을 미지의 차단으로 폴백 처리."""
if product_count > 0:
return None
marker = next((m for m in _BLOCK_MARKERS if m in html), None)
if marker is None and len(html) < _MIN_RESULT_HTML:
marker = f"short_html({len(html)}B)"
return marker
class CoupangAdapter(SearchAdapter):
source = "coupang"
@@ -113,8 +136,8 @@ class CoupangAdapter(SearchAdapter):
LOG.d(f"[coupang] query={query!r} → {len(products)}건 (limit {limit}, ip_req#{self._ip_requests})")
return products[:limit]
# 0건 — 봇 감지 여부 판정
marker = next((m for m in _BLOCK_MARKERS if m in html), None)
# 0건 — 차단 여부 판정(알려진 마커 + 짧은 HTML 폴백)
marker = detect_block(html, len(products))
blocked = marker is not None
self._blocked += 1
if blocked: