fix handler errors

This commit is contained in:
Aron Petau 2026-01-02 12:25:27 +01:00
parent e6b0f844fe
commit c68ee12d4e
3 changed files with 70 additions and 20 deletions

View file

@ -31,20 +31,44 @@ class StadtUndLandHandler(BaseHandler):
logger.info("[STADTUNDLAND] Page loaded")
await asyncio.sleep(2)
# Dismiss cookie banner
try:
cookie_btn = await page.query_selector('button:has-text("Akzeptieren"), button:has-text("Alle akzeptieren")')
if cookie_btn and await cookie_btn.is_visible():
await cookie_btn.click()
logger.info("[STADTUNDLAND] Dismissed cookie banner")
await asyncio.sleep(1)
except Exception as e:
logger.debug(f"[STADTUNDLAND] Cookie banner dismiss failed: {e}")
# Always handle cookies and consent
await self.handle_cookies(page)
await self.handle_consent(page)
await asyncio.sleep(1)
# Check for 404 or error page early
page_title = await page.title()
page_content = await page.content()
# Check for error messages
if "schief gelaufen" in page_content.lower() or "schief gelaufen" in page_title.lower():
logger.warning(f"[STADTUNDLAND] Error page detected (schief gelaufen) for {listing['link']}")
result["success"] = False
result["details"] = "Listing no longer available (error page)"
await page.screenshot(path=str(DATA_DIR / f"stadtundland_404_{listing['id']}.png"))
return result
# Check for "nicht verfügbar" or similar messages
if "nicht verfügbar" in page_content.lower() or "nicht mehr" in page_content.lower():
logger.warning(f"[STADTUNDLAND] Listing not available: {listing['link']}")
result["success"] = False
result["details"] = "Listing no longer available"
await page.screenshot(path=str(DATA_DIR / f"stadtundland_404_{listing['id']}.png"))
return result
# Scroll to form
await page.evaluate("window.scrollBy(0, 500)")
await asyncio.sleep(0.5)
# Save HTML for debugging
try:
html_content = await page.content()
with open(DATA_DIR / f"stadtundland_debug_{listing['id']}.html", "w", encoding="utf-8") as f:
f.write(html_content)
logger.debug(f"[STADTUNDLAND] Saved debug HTML")
except Exception as e:
logger.warning(f"[STADTUNDLAND] Could not save debug HTML: {e}")
# Fill out the embedded form directly
form_filled = False
try: