Skip to content

Commit 8b14c2c

Browse files
committed
장소 정보 추출값 중 길찾기 안내 Section 정보가 끝까지 출력되지않는 문제 : feat : # "찾아가는 길" 더보기 버튼 클릭 (전체 텍스트 펼치기) 구현 #16
1 parent b6ecb89 commit 8b14c2c

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/services/scraper/platforms/naver_map_scraper.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
네이버 지도 장소 스크래핑 로직
33
"""
44
import logging
5-
import asyncio
65
from urllib.parse import quote
76

87
from playwright.async_api import async_playwright
@@ -14,7 +13,6 @@
1413
parse_rating,
1514
extract_naver_place_id_from_url,
1615
SCRAPE_TIMEOUT_MS,
17-
PAGE_LOAD_WAIT_SEC,
1816
ELEMENT_WAIT_TIMEOUT_MS,
1917
MAX_IMAGE_COUNT,
2018
)
@@ -107,9 +105,8 @@ async def search_and_scrape(self, query: str) -> NaverPlaceInfo:
107105

108106
logger.info("첫 번째 결과 클릭 완료, 상세 페이지 로드 대기...")
109107

110-
# [5/7] 상세 페이지 로드 대기
108+
# [5/7] 상세 페이지 로드 대기 (entryIframe이 나타날 때까지)
111109
logger.info("[5/7] 상세 페이지 로드 대기...")
112-
await asyncio.sleep(PAGE_LOAD_WAIT_SEC)
113110

114111
# entryIframe 대기
115112
logger.info("entryIframe 대기...")
@@ -149,8 +146,22 @@ async def search_and_scrape(self, query: str) -> NaverPlaceInfo:
149146

150147
logger.debug(f"entry_frame URL: {entry_frame.url}")
151148

152-
# 추가 대기: DOM이 완전히 로드될 때까지
153-
await asyncio.sleep(2)
149+
# DOM 완전 로드 대기 (주소 요소가 나타날 때까지)
150+
try:
151+
await entry_frame.wait_for_selector('span.LDgIH', timeout=ELEMENT_WAIT_TIMEOUT_MS)
152+
except Exception:
153+
pass # 주소가 없는 장소도 있으므로 무시
154+
155+
# "찾아가는 길" 더보기 버튼 클릭 (전체 텍스트 펼치기)
156+
try:
157+
directions_expand_button = entry_frame.locator('a.xHaT3[aria-expanded="false"]')
158+
if await directions_expand_button.count() > 0:
159+
await directions_expand_button.first.click()
160+
# 펼쳐진 상태 대기
161+
await entry_frame.wait_for_selector('a.xHaT3[aria-expanded="true"]', timeout=2000)
162+
logger.debug("찾아가는 길 더보기 클릭 완료")
163+
except Exception as error:
164+
logger.debug(f"찾아가는 길 더보기 클릭 실패 (무시): {error}")
154165

155166
# iframe 내에서 JavaScript 실행
156167
info = await entry_frame.evaluate(f'''() => {{
@@ -204,8 +215,10 @@ async def search_and_scrape(self, query: str) -> NaverPlaceInfo:
204215
const subwayElement = document.querySelector('div.nZapA');
205216
result.subway_info = subwayElement ? subwayElement.textContent.trim() : null;
206217
207-
// 찾아가는 길
208-
const directionsElement = document.querySelector('span.zPfVt') ||
218+
// 찾아가는 길 (전체 텍스트 - 펼쳐진 상태 우선)
219+
const expandedDirections = document.querySelector('a.xHaT3[aria-expanded="true"] span.zPfVt');
220+
const directionsElement = expandedDirections ||
221+
document.querySelector('span.zPfVt') ||
209222
document.querySelector('.place_section_content .zPfVt');
210223
result.directions_text = directionsElement ? directionsElement.textContent.trim() : null;
211224

0 commit comments

Comments
 (0)