업체명+URL 검색 통합 및 요식업종 가하도록 추가
This commit is contained in:
1 parent
d1fe7fcd5f
commit
009b1a5d09
12 files changed
+136
-276
No files matched your search
+17
-10
@@ -72,6 +72,7 @@ query getAccommodation($id: String!, $deviceType: String) {
|
||||
self.image_link_list: list[str] | None = None
|
||||
self.base_info: dict | None = None
|
||||
self.facility_info: str | None = None
|
||||
self.place_type: str | None = None # 크롤링으로 감지된 업종 (accommodation | restaurant)
|
||||
|
||||
def _get_request_headers(self) -> dict:
|
||||
headers = self.DEFAULT_HEADERS.copy()
|
||||
@@ -95,7 +96,12 @@ query getAccommodation($id: String!, $deviceType: String) {
|
||||
match = re.search(place_pattern, self.url)
|
||||
if not match:
|
||||
# place.naver.com/{type}/{id} 형식 (예: m.place.naver.com/restaurant/11667161)
|
||||
match = re.search(r"place\.naver\.com/[a-zA-Z]+/(\d+)", self.url)
|
||||
type_match = re.search(r"place\.naver\.com/([a-zA-Z]+)/(\d+)", self.url)
|
||||
if type_match:
|
||||
url_place_type = type_match.group(1)
|
||||
if url_place_type in ("accommodation", "restaurant"):
|
||||
self.place_type = url_place_type
|
||||
return type_match.group(2)
|
||||
if not match:
|
||||
raise URLNotFoundException("Failed to parse place ID from URL")
|
||||
return match[1]
|
||||
@@ -167,7 +173,7 @@ query getAccommodation($id: String!, $deviceType: String) {
|
||||
raise GraphQLException(f"Client error: {e}")
|
||||
|
||||
async def _get_facility_string(self, place_id: str) -> str | None:
|
||||
"""숙소 페이지에서 편의시설 정보를 크롤링합니다.
|
||||
"""장소 페이지에서 편의시설 정보를 크롤링합니다. 숙소, 음식점 순으로 시도합니다.
|
||||
|
||||
Args:
|
||||
place_id: 네이버 지도 장소 ID
|
||||
@@ -175,16 +181,17 @@ query getAccommodation($id: String!, $deviceType: String) {
|
||||
Returns:
|
||||
편의시설 정보 문자열 또는 None
|
||||
"""
|
||||
url = f"https://pcmap.place.naver.com/accommodation/{place_id}/home"
|
||||
place_types = ["accommodation", "restaurant"]
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url, headers=self._get_request_headers()) as response:
|
||||
soup = bs4.BeautifulSoup(await response.read(), "html.parser")
|
||||
c_elem = soup.find("span", "place_blind", string="편의")
|
||||
if c_elem:
|
||||
facilities = c_elem.parent.parent.find("div").string
|
||||
return facilities
|
||||
return None
|
||||
for place_type in place_types:
|
||||
url = f"https://pcmap.place.naver.com/{place_type}/{place_id}/home"
|
||||
async with session.get(url, headers=self._get_request_headers()) as response:
|
||||
soup = bs4.BeautifulSoup(await response.read(), "html.parser")
|
||||
c_elem = soup.find("span", "place_blind", string="편의")
|
||||
if c_elem:
|
||||
return c_elem.parent.parent.find("div").string
|
||||
return None
|
||||
except Exception as e:
|
||||
logger.warning(f"[NvMapScraper] Failed to get facility info: {e}")
|
||||
return None
|
||||
|
||||
Reference in new issue
Block a user