Files
hotels/find_api.py
Фёдор 0cf3297290 Проект аудита отелей: основные скрипты и документация
- Краулеры: smart_crawler.py, regional_crawler.py
- Аудит: audit_orel_to_excel.py, audit_chukotka_to_excel.py
- РКН проверка: check_rkn_registry.py, recheck_unclear_rkn.py
- Отчёты: create_orel_horizontal_report.py
- Обработка: process_all_hotels_embeddings.py
- Документация: README.md, DB_SCHEMA_REFERENCE.md
2025-10-16 10:52:09 +03:00

84 lines
3.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""Скрипт для поиска API endpoint'ов"""
import asyncio
import json
from playwright.async_api import async_playwright
async def find_api_endpoints():
api_calls = []
async with async_playwright() as p:
browser = await p.chromium.launch(headless=True)
page = await browser.new_page()
# Перехватываем все запросы
async def log_request(response):
url = response.url
# Интересуют только API запросы
if '/api/' in url:
try:
status = response.status
method = response.request.method
data = {
'url': url,
'method': method,
'status': status,
}
# Пытаемся получить тело ответа для успешных запросов
if status == 200:
try:
body = await response.json()
data['response_sample'] = str(body)[:500] # Первые 500 символов
except:
pass
api_calls.append(data)
print(f"[{method}] {status} - {url}")
except Exception as e:
print(f"Error processing {url}: {e}")
page.on('response', log_request)
print("Загружаем страницу со списком отелей...")
await page.goto('https://tourism.fsa.gov.ru/ru/resorts/showcase/hotels',
wait_until='networkidle',
timeout=60000)
print("\nОжидаем загрузку данных...")
await page.wait_for_timeout(5000)
# Пробуем прокрутить страницу для загрузки дополнительных данных
await page.evaluate('window.scrollTo(0, document.body.scrollHeight)')
await page.wait_for_timeout(2000)
await browser.close()
# Сохраняем результаты
with open('api_endpoints.json', 'w', encoding='utf-8') as f:
json.dump(api_calls, f, ensure_ascii=False, indent=2)
print(f"\n\nНайдено {len(api_calls)} API запросов")
print("Результаты сохранены в api_endpoints.json")
# Выводим уникальные endpoint'ы
unique_endpoints = set()
for call in api_calls:
# Убираем параметры запроса для группировки
url = call['url'].split('?')[0]
unique_endpoints.add((call['method'], url))
print("\n=== Уникальные endpoint'ы ===")
for method, url in sorted(unique_endpoints):
print(f"[{method}] {url}")
if __name__ == "__main__":
asyncio.run(find_api_endpoints())