fix: _parse

This commit is contained in:
austnv
2026-06-14 16:46:18 +03:00
parent ba960d5d67
commit a2d57c4080
+16 -7
View File
@@ -66,17 +66,26 @@ class IPInfo:
def _parse(self, html: str) -> Optional[IPInfoModel]: def _parse(self, html: str) -> Optional[IPInfoModel]:
"""Парсит HTML и возвращает модель""" """Парсит HTML и возвращает модель"""
soup = BeautifulSoup(html, 'html.parser') soup = BeautifulSoup(html, 'html.parser')
script = soup.find('script', type='application/ld+json') scripts = soup.find_all('script', type='application/ld+json')
if not script or not script.string: if not scripts:
return None return None
try: # Ищем первый скрипт с типом DataFeed
data: Dict = json.loads(script.string.strip()) data = None
except json.JSONDecodeError: for script in scripts:
return None if not script.string:
continue
if data.get('@type') != 'DataFeed': try:
parsed = json.loads(script.string.strip())
if parsed.get('@type') == 'DataFeed':
data = parsed
break
except json.JSONDecodeError:
continue
if data is None:
return None return None
# Базовые поля # Базовые поля