Klappe Geizhals-Filtergruppen beim Lernen auf und nimm neue Kategorien ueber den Quellpfad auf.
Deploy Development / deploy (push) Successful in 1m34s
Test Suite / pytest-backend (push) Failing after 16s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-checks (push) Successful in 33s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-04 15:04:19 +02:00
1 parent 46857715df
commit 2117ca6b54
10 files changed
+203 -25

No files matched your search

+32 -11
View File
@@ -15,6 +15,8 @@ BROWSER_HEADERS = {
"Accept-Language": "de-DE,de;q=0.9,en;q=0.8",
}
EXPAND_LABELS = (
"Erweiterte Filter",
"Alle Filter ausklappen",
"Immer alle Filter anzeigen",
"weitere Filter anzeigen",
)
@@ -42,19 +44,19 @@ def load_result_page(url: str, *, playwright: bool = True) -> tuple[str, str, in
def load_category_page(url: str, *, category_ref: str, playwright: bool = True) -> tuple[str, str, int]:
status, html = 0, ""
if playwright:
try:
status, html = _fetch_playwright(url, expand_filters=True)
if not _blocked(status, html):
return html, "live_playwright", status
except Exception:
pass
try:
status, html = _fetch_http(url)
if not _blocked(status, html):
return html, "live_http", status
except Exception:
status, html = 0, ""
if playwright:
try:
status, html = _fetch_playwright(url)
if not _blocked(status, html):
return html, "live_playwright", status
except Exception:
pass
status, html = status or 0, html or ""
recorded = FIXTURE_DIR / f"{category_ref}-category.html"
if recorded.exists():
return recorded.read_text(encoding="utf-8"), "recorded_html", 0
@@ -73,7 +75,7 @@ def _fetch_http(url: str) -> tuple[int, str]:
return response.status_code, response.text
def _fetch_playwright(url: str) -> tuple[int, str]:
def _fetch_playwright(url: str, *, expand_filters: bool = False) -> tuple[int, str]:
try:
from playwright.sync_api import sync_playwright
except ImportError as exc:
@@ -87,17 +89,36 @@ def _fetch_playwright(url: str) -> tuple[int, str]:
page = browser.new_page(locale="de-DE", extra_http_headers=BROWSER_HEADERS)
response = page.goto(url, wait_until="domcontentloaded", timeout=45000)
page.wait_for_timeout(4000)
if expand_filters:
_expand_filter_sections(page)
for label in EXPAND_LABELS:
button = page.get_by_text(label, exact=False)
if button.count():
button.first.click(timeout=5000)
page.wait_for_timeout(1500)
try:
button.first.click(timeout=4000)
page.wait_for_timeout(800)
except Exception:
continue
if expand_filters:
_expand_filter_sections(page)
html = page.content()
status = response.status if response is not None else 200
browser.close()
return status, html
def _expand_filter_sections(page: object) -> None:
locator = page.locator('button[aria-label*="aufklappen"]')
for _ in range(40):
if locator.count() == 0:
return
try:
locator.first.click(timeout=3000)
page.wait_for_timeout(700)
except Exception:
return
def _blocked(status: int, html: str) -> bool:
if status in {401, 403, 429}:
return True