"""Прогнать current parser на HTML из Playwright debug-страницы (своб.планир p=10). Проверяет что URL-filter работает: до фикса parser возвращал ~30 карточек других городов, после — должен 0 или только ЕКБ. """ from __future__ import annotations import asyncio import sys import types from pathlib import Path _BACKEND = Path(__file__).resolve().parent.parent / "backend" if str(_BACKEND) not in sys.path: sys.path.insert(0, str(_BACKEND)) for _m in ("weasyprint", "weasyprint.text", "weasyprint.text.ffi", "weasyprint.css", "weasyprint.css.targets"): sys.modules[_m] = types.ModuleType(_m) sys.modules["weasyprint"].HTML = type("HTML", (), {"__init__": lambda self, *a, **kw: None}) sys.modules["weasyprint"].CSS = type("CSS", (), {"__init__": lambda self, *a, **kw: None}) from app.services.scrapers.avito import AvitoScraper # noqa: E402 URL = "https://www.avito.ru/ekaterinburg/kvartiry/prodam/svobodnaya_planirovka-ASgBAgICAkSSA8YQygj8zzI?p=10&s=104" async def main() -> None: async with AvitoScraper() as s: assert s._cffi is not None # Use scraper's own session — может попасть в 403 (curl_cffi), это OK, # тогда переключимся на reading from Playwright MCP page. print(f"Fetching {URL[:80]}...") try: r = await s._cffi.get(URL) print(f" HTTP {r.status_code}, html size: {len(r.text)}") if r.status_code != 200: print(" curl_cffi 403 — Avito не отдал. Пробни через MCP / browser save.") return except Exception as e: # noqa: BLE001 print(f" fetch fail: {type(e).__name__}: {e}") return lots = s._parse_html(r.text, source_url_base=URL) print(f"\nParsed {len(lots)} EKB lots (после фильтра).") for lot in lots[:5]: print(f" {lot.source_id} {lot.source_url[:80]}") print(f" {lot.address or '-'!r}") if __name__ == "__main__": asyncio.run(main())