fix(crawling): homepages를 GraphQL 대신 __APOLLO_STATE__에서 추출

placeDetail(base)의 homepages 필드는 스키마에 없어 전체 크롤링이
400으로 실패했다(컨테이너 검증 완료). 쿼리에서 제거하고, WTM 우회용
브라우저가 이미 로드하는 place 페이지의 __APOLLO_STATE__ JSON을 캡처해
대표(repr) 링크를 추출한다. 브라우저 캡처 실패 시 HTML 직접 파싱으로
보충한다(직접 요청은 429로 막히는 환경이 있어 best-effort).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVSeUT2pEmeHc6hG6gVXUS
This commit is contained in:
HyeongBaeYangandClaude Fable 5 committed 2026-08-21 11:30:01 +09:00
1 parent 87cb3eb3cb
commit 6197fcdc91
2 files changed
+88 -35

No files matched your search

+23 -5
View File
@@ -131,7 +131,8 @@ if (originalQuery) {
cls,
place_id: str,
payloads: list[dict],
) -> list[dict | None] | None:
capture_apollo: bool = False,
) -> list[dict | None] | None | tuple[list[dict | None] | None, str | None]:
"""실제 브라우저로 네이버 WTM 안티봇 캡차를 통과해 GraphQL 쿼리를 실행한다.
네이버 pcmap GraphQL은 두 헤더를 검사한다:
@@ -144,12 +145,19 @@ if (originalQuery) {
Args:
place_id: 네이버 place ID
payloads: GraphQL POST 본문 목록
capture_apollo: True면 place 페이지에 인라인된 __APOLLO_STATE__
JSON 문자열도 함께 캡처해 (results, apollo_json) 튜플로 반환.
(GraphQL base가 노출하지 않는 homepages 등 SSR 캐시 전용 필드용)
Returns:
payload별 파싱 JSON 목록(실패 항목은 None). 토큰 캡처 실패 시 None.
capture_apollo=True면 (위 결과, apollo_json 또는 None) 튜플.
"""
def _ret(results, apollo=None):
return (results, apollo) if capture_apollo else results
if not cls.is_ready:
logger.warning("[NvMapPwScraper] fetch_graphql: scraper가 초기화되지 않았습니다")
return None
return _ret(None)
page = await cls._new_stealth_page()
captured: dict = {}
@@ -185,7 +193,17 @@ if (originalQuery) {
if not captured.get("tok"):
logger.warning("[NvMapPwScraper] WTM 토큰 캡처 실패")
return None
return _ret(None)
apollo_json: str | None = None
if capture_apollo:
try:
apollo_json = await page.evaluate(
"() => { try { return JSON.stringify(window.__APOLLO_STATE__ || null); }"
" catch (e) { return null; } }"
)
except Exception as e:
logger.warning(f"[NvMapPwScraper] __APOLLO_STATE__ 캡처 실패: {e}")
headers = {
"Content-Type": "application/json",
@@ -220,11 +238,11 @@ if (originalQuery) {
results.append(None)
else:
results.append(r)
return results
return _ret(results, apollo_json)
except Exception as e:
logger.error(f"[NvMapPwScraper] fetch_graphql 오류: {e}")
return None
return _ret(None)
finally:
await page.close()