feat(lps): DECODO residential 프록시 — 쿠팡 sticky 세션 + 주기적 IP 회전

datacenter IP + Akamai 대응. 매 요청 IP 변경은 쿠키-IP 불일치로 재챌린지를
유발하므로, sticky 세션(일정 시간 같은 IP) + 주기적 회전 방식 사용.

- search/proxy.DecodoProxy: username 에 -session-<시간창id>-sessionduration-<분> 부착
  → 창 안에선 같은 IP, 창이 지나면 새 IP. 자격증명은 .env(DECODO_*), 4개 다 있어야 활성
- coupang/adapter: proxy 주입 + 세션창 경과 시 브라우저 재기동(IP 회전). 무프록시면 직접 연결
- worker_main: 쿠팡에만 DecodoProxy 경유(네이버는 공식 API라 미적용)
- .env.example: DECODO_HOST/PORT/USERNAME/PASSWORD/SESSION_MINUTES 슬롯
- tests: 활성조건·sticky username·server형식·세션창 회전 4건 → 전체 43/43

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:40:26 +09:00
1 parent d54dee4f24
commit 4de85d43ed
5 files changed
+120 -25

No files matched your search

+29 -9
View File
@@ -9,6 +9,7 @@ persistent context 로 브라우저를 재사용하므로 챌린지는 (쿠키
"""
import asyncio
import time
from urllib.parse import quote
from patchright.async_api import async_playwright
@@ -26,26 +27,45 @@ _BLOCK_MARKERS = ("sec-if-cpt-container", "Powered and protected", "/akam/")
class CoupangAdapter(SearchAdapter):
source = "coupang"
def __init__(self, headless: bool = False, user_data_dir: str = "/tmp/lps_coupang_profile", rate_limiter: RateLimiter | None = None):
def __init__(self, headless: bool = False, user_data_dir: str = "/tmp/lps_coupang_profile", rate_limiter: RateLimiter | None = None, proxy=None):
self._headless = headless
self._user_data_dir = user_data_dir
self._rl = rate_limiter or RateLimiter()
self._proxy = proxy # DecodoProxy 등 (없으면 직접 연결)
self._pw = None
self._ctx = None
self._launched_at = 0.0
self._lock = asyncio.Lock()
self._ok = 0
self._blocked = 0
def _recycle_due(self) -> bool:
"""프록시 sticky 세션창이 지났으면 브라우저를 재기동해 새 IP 를 받는다."""
if not (self._proxy and self._proxy.enabled):
return False
return (time.monotonic() - self._launched_at) > self._proxy.session_minutes * 60
async def _ensure_browser(self):
if self._ctx is not None:
return
self._pw = await async_playwright().start()
self._ctx = await self._pw.chromium.launch_persistent_context(
user_data_dir=self._user_data_dir,
channel="chrome",
headless=self._headless,
no_viewport=True,
)
if self._recycle_due():
LOG.d("[coupang] 프록시 세션창 경과 → 브라우저 재기동(IP 회전)")
await self._close_ctx()
else:
return
if self._pw is None:
self._pw = await async_playwright().start()
kwargs = dict(user_data_dir=self._user_data_dir, channel="chrome", headless=self._headless, no_viewport=True)
if self._proxy and self._proxy.enabled:
kwargs["proxy"] = self._proxy.playwright_proxy()
self._ctx = await self._pw.chromium.launch_persistent_context(**kwargs)
self._launched_at = time.monotonic()
async def _close_ctx(self):
if self._ctx is not None:
try:
await self._ctx.close()
finally:
self._ctx = None
async def search(self, query: str, limit: int = 40) -> list[NormalizedProduct]:
async with self._lock: # 인스턴스 내 검색은 직렬화(브라우저 컨텍스트 공유)