working app
This commit is contained in:
parent
8e69e30387
commit
3057cda8d3
12 changed files with 708 additions and 232 deletions
|
|
@ -11,10 +11,22 @@ class GesobauHandler(BaseHandler):
|
|||
async def apply(self, listing: dict, result: dict) -> dict:
|
||||
page = await self.context.new_page()
|
||||
try:
|
||||
logger.info(f"[GESOBAU] Open: {listing['link']}")
|
||||
await page.goto(listing["link"], wait_until="networkidle")
|
||||
logger.info(f"[GESOBAU] Opening page: {listing['link']}")
|
||||
response = await page.goto(listing["link"], wait_until="networkidle")
|
||||
logger.info("[GESOBAU] Page loaded")
|
||||
await asyncio.sleep(2)
|
||||
|
||||
# 404 detection
|
||||
status = response.status if response else None
|
||||
page_title = await page.title()
|
||||
if status == 404 or (page_title and "404" in page_title):
|
||||
logger.warning(f"[GESOBAU] Listing is down (404): {listing['link']}")
|
||||
result["success"] = False
|
||||
result["message"] = "Listing is no longer available (404). Application impossible. Will not retry."
|
||||
result["permanent_fail"] = True
|
||||
await page.close()
|
||||
return result
|
||||
|
||||
# Always handle cookies and consent before anything else
|
||||
await self.handle_cookies(page)
|
||||
await self.handle_consent(page)
|
||||
|
|
@ -63,8 +75,47 @@ class GesobauHandler(BaseHandler):
|
|||
await asyncio.sleep(0.5)
|
||||
await apply_btn.click()
|
||||
await asyncio.sleep(2)
|
||||
result["success"] = True
|
||||
result["message"] = "Application submitted successfully."
|
||||
# --- Post-click confirmation logic ---
|
||||
logger.info("[GESOBAU] Clicked application button, checking for confirmation...")
|
||||
# Save screenshot and HTML after click
|
||||
try:
|
||||
await page.screenshot(path="data/gesobau_after_apply.png")
|
||||
logger.info("[GESOBAU] Saved screenshot after application click.")
|
||||
except Exception as e:
|
||||
logger.warning(f"[GESOBAU] Could not save screenshot: {e}")
|
||||
try:
|
||||
html_after = await page.content()
|
||||
with open("data/gesobau_after_apply.html", "w", encoding="utf-8") as f:
|
||||
f.write(html_after)
|
||||
logger.info("[GESOBAU] Saved HTML after application click.")
|
||||
except Exception as e:
|
||||
logger.warning(f"[GESOBAU] Could not save HTML after apply: {e}")
|
||||
|
||||
# Look for confirmation message on the page
|
||||
confirmation_selectors = [
|
||||
'text="Vielen Dank"',
|
||||
'text="Ihre Anfrage wurde gesendet"',
|
||||
'text="Bestätigung"',
|
||||
'div:has-text("Vielen Dank")',
|
||||
'div:has-text("Ihre Anfrage wurde gesendet")',
|
||||
]
|
||||
confirmed = False
|
||||
for sel in confirmation_selectors:
|
||||
try:
|
||||
el = await page.query_selector(sel)
|
||||
if el and await el.is_visible():
|
||||
logger.info(f"[GESOBAU] Found confirmation element: {sel}")
|
||||
confirmed = True
|
||||
break
|
||||
except Exception as e:
|
||||
logger.debug(f"[GESOBAU] Error checking confirmation selector {sel}: {e}")
|
||||
if confirmed:
|
||||
result["success"] = True
|
||||
result["message"] = "Application submitted and confirmation detected."
|
||||
else:
|
||||
logger.warning("[GESOBAU] No confirmation message detected after application click.")
|
||||
result["success"] = False
|
||||
result["message"] = "Clicked application button, but no confirmation detected. Check screenshot and HTML."
|
||||
else:
|
||||
logger.warning("[GESOBAU] No application button found.")
|
||||
result["message"] = "No application button found."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue