roughly working again, now dev docker exists

This commit is contained in:
Aron Petau 2025-12-28 19:59:31 +01:00
parent a77a0c0393
commit 155ab39368
26 changed files with 1976 additions and 235 deletions

View file

@ -5,50 +5,78 @@ import asyncio
logger = logging.getLogger(__name__)
class StadtUndLandHandler(BaseHandler):
def __init__(self, browser_context):
self.context = browser_context
async def apply(self, listing: dict, result: dict) -> dict:
page = await self.context.new_page()
try:
logger.info(f"[STADT UND LAND] Opening page: {listing['link']}")
logger.info(f"[STADT UND LAND] Open: {listing['link']}")
await page.goto(listing["link"], wait_until="networkidle")
logger.info("[STADT UND LAND] Page loaded")
await asyncio.sleep(2)
# Handle cookies and consent
# Always handle cookies and consent before anything else
await self.handle_cookies(page)
await self.handle_consent(page)
# Look for application button
logger.info("[STADT UND LAND] Looking for application button...")
# Save HTML after modal handling for debugging
try:
html_content = await page.content()
with open("data/stadtundland_debug.html", "w", encoding="utf-8") as f:
f.write(html_content)
except Exception as e:
logger.debug(f"[STADT UND LAND] Debug HTML not saved: {e}")
# 404/permanent fail detection
error_texts = [
"Hier ist etwas schief gelaufen",
"Leider können wir Ihnen zur Zeit keine Details zu diesem Inserat anzeigen"
]
page_text = await page.text_content('body')
if page_text:
for err in error_texts:
if err in page_text:
logger.warning(f"[STADT UND LAND] Permanent fail: {err}")
result["permanent_fail"] = True
result["message"] = "Listing is no longer available (404 detected on STADT UND LAND)."
await page.close()
return result
# Look for application button (robust selectors)
logger.info("[STADT UND LAND] Searching for application button...")
selectors = [
'a[href*="bewerben"]',
'button:has-text("Bewerben")'
'button:has-text("Bewerben")',
'a:has-text("Bewerben")',
'button.btn',
'a.Button_button__JnZ4E',
'button.Button_button__JnZ4E',
]
apply_btn = None
for sel in selectors:
all_btns = await page.query_selector_all(sel)
logger.info(f"[STADT UND LAND] Selector '{sel}' found {len(all_btns)} matches")
logger.debug(f"[STADT UND LAND] Selector '{sel}': {len(all_btns)} matches")
for btn in all_btns:
try:
if await btn.is_visible():
apply_btn = btn
logger.info(f"[STADT UND LAND] Found visible button with selector '{sel}'")
logger.info(f"[STADT UND LAND] Found visible application button: {sel}")
break
except Exception as e:
logger.warning(f"[STADT UND LAND] Error checking button visibility: {e}")
logger.debug(f"[STADT UND LAND] Button visibility error: {e}")
if apply_btn:
break
if apply_btn:
logger.info("[STADT UND LAND] Found application button, scrolling into view...")
await apply_btn.scroll_into_view_if_needed()
await asyncio.sleep(0.5)
logger.info("[STADT UND LAND] Clicking button...")
await apply_btn.click()
await asyncio.sleep(2)
result["success"] = True
result["message"] = "Application submitted successfully."
else:
logger.warning("[STADT UND LAND] No application button found.")
result["message"] = "No application button found."
except Exception as e:
result["message"] = f"Error during application: {e}"