url 에러 시 404 출력

This commit is contained in:
dhlim committed 2026-04-03 01:23:43 +00:00
1 parent cc7ee58006
commit 0fd028a49f
3 files changed
+32 -25

No files matched your search

+20 -22
View File
@@ -16,6 +16,10 @@ class GraphQLException(Exception):
"""GraphQL 요청 실패 시 발생하는 예외"""
pass
class URLNotFoundException(Exception):
"""Place ID 발견 불가능 시 발생하는 예외"""
pass
class CrawlingTimeoutException(Exception):
"""크롤링 타임아웃 시 발생하는 예외"""
@@ -86,34 +90,28 @@ query getAccommodation($id: String!, $deviceType: String) {
async with session.get(self.url) as response:
self.url = str(response.url)
else:
raise GraphQLException("This URL does not contain a place ID")
raise URLNotFoundException("This URL does not contain a place ID")
match = re.search(place_pattern, self.url)
if not match:
raise GraphQLException("Failed to parse place ID from URL")
raise URLNotFoundException("Failed to parse place ID from URL")
return match[1]
async def scrap(self):
try:
place_id = await self.parse_url()
data = await self._call_get_accommodation(place_id)
self.rawdata = data
fac_data = await self._get_facility_string(place_id)
# Naver 기준임, 구글 등 다른 데이터 소스의 경우 고유 Identifier 사용할 것.
self.place_id = self.data_source_identifier + place_id
self.rawdata["facilities"] = fac_data
self.image_link_list = [
nv_image["origin"]
for nv_image in data["data"]["business"]["images"]["images"]
]
self.base_info = data["data"]["business"]["base"]
self.facility_info = fac_data
self.scrap_type = "GraphQL"
except GraphQLException:
logger.debug("GraphQL failed, fallback to Playwright")
self.scrap_type = "Playwright"
pass # 나중에 pw 이용한 crawling으로 fallback 추가
place_id = await self.parse_url()
data = await self._call_get_accommodation(place_id)
self.rawdata = data
fac_data = await self._get_facility_string(place_id)
# Naver 기준임, 구글 등 다른 데이터 소스의 경우 고유 Identifier 사용할 것.
self.place_id = self.data_source_identifier + place_id
self.rawdata["facilities"] = fac_data
self.image_link_list = [
nv_image["origin"]
for nv_image in data["data"]["business"]["images"]["images"]
]
self.base_info = data["data"]["business"]["base"]
self.facility_info = fac_data
self.scrap_type = "GraphQL"
return