feat(lps): DECODO 포트기반 sticky + 대역폭 최적화(리소스 차단)

대시보드 실측 반영 — Decodo residential 은 포트 기반 sticky(gate:10001..N,
고정 user/pass, 각 포트=sticky 세션). IP 회전 = 포트 순환.

- proxy.DecodoProxy: 시간창 기반 포트 선택(창 안 동일 IP, 창 지나면 다음 포트=새 IP).
  _UNSET sentinel 로 '미지정(env)' vs '명시적 빈값' 구분(테스트 결정성)
- coupang/adapter: 이미지/미디어/폰트/CSS 차단(block_resources) — per-GB 대역폭 대폭 절감,
  Akamai(JS)·상품파싱엔 무영향. 라이브 검증: 차단 ON 에도 Akamai 통과+파싱 정상
- .env.example: DECODO_HOST/USERNAME/PASSWORD/PORT_START/PORT_END/SESSION_MINUTES
- tests: 포트범위/시간창 안정성/활성조건 5건 → 전체 44/44

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
민헌andClaude Opus 4.8 committed 2026-07-09 09:48:54 +09:00
1 parent 4de85d43ed
commit 2481c79e3f
4 files changed
+75 -57

No files matched your search

+12 -1
View File
@@ -22,16 +22,19 @@ 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/")
# 대역폭 절감: 이미지/미디어/폰트/CSS 는 상품 데이터·Akamai(JS) 에 불필요 → 차단(프록시 per-GB 비용↓).
_BLOCKED_RESOURCES = {"image", "media", "font", "stylesheet"}
class CoupangAdapter(SearchAdapter):
source = "coupang"
def __init__(self, headless: bool = False, user_data_dir: str = "/tmp/lps_coupang_profile", rate_limiter: RateLimiter | None = None, proxy=None):
def __init__(self, headless: bool = False, user_data_dir: str = "/tmp/lps_coupang_profile", rate_limiter: RateLimiter | None = None, proxy=None, block_resources: bool = True):
self._headless = headless
self._user_data_dir = user_data_dir
self._rl = rate_limiter or RateLimiter()
self._proxy = proxy # DecodoProxy 등 (없으면 직접 연결)
self._block_resources = block_resources
self._pw = None
self._ctx = None
self._launched_at = 0.0
@@ -39,6 +42,12 @@ class CoupangAdapter(SearchAdapter):
self._ok = 0
self._blocked = 0
async def _route(self, route):
if route.request.resource_type in _BLOCKED_RESOURCES:
await route.abort()
else:
await route.continue_()
def _recycle_due(self) -> bool:
"""프록시 sticky 세션창이 지났으면 브라우저를 재기동해 새 IP 를 받는다."""
if not (self._proxy and self._proxy.enabled):
@@ -58,6 +67,8 @@ class CoupangAdapter(SearchAdapter):
if self._proxy and self._proxy.enabled:
kwargs["proxy"] = self._proxy.playwright_proxy()
self._ctx = await self._pw.chromium.launch_persistent_context(**kwargs)
if self._block_resources:
await self._ctx.route("**/*", self._route) # 이미지/미디어/폰트/CSS 차단
self._launched_at = time.monotonic()
async def _close_ctx(self):