59 lines
No EOL
2.3 KiB
Python
59 lines
No EOL
2.3 KiB
Python
from .base_handler import BaseHandler
|
|
import logging
|
|
import asyncio
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class GesobauHandler(BaseHandler):
|
|
async def apply(self, listing: dict, result: dict) -> dict:
|
|
page = await self.context.new_page()
|
|
try:
|
|
logger.info(f"[GESOBAU] Opening page: {listing['link']}")
|
|
await page.goto(listing["link"], wait_until="networkidle")
|
|
logger.info("[GESOBAU] Page loaded")
|
|
await asyncio.sleep(2)
|
|
|
|
# Handle cookies and consent
|
|
await self.handle_cookies(page)
|
|
await self.handle_consent(page)
|
|
|
|
# Look for application button
|
|
logger.info("[GESOBAU] Looking for application button...")
|
|
selectors = [
|
|
'a[href*="bewerben"]',
|
|
'button:has-text("Bewerben")'
|
|
]
|
|
|
|
apply_btn = None
|
|
for sel in selectors:
|
|
all_btns = await page.query_selector_all(sel)
|
|
logger.info(f"[GESOBAU] Selector '{sel}' found {len(all_btns)} matches")
|
|
for btn in all_btns:
|
|
try:
|
|
if await btn.is_visible():
|
|
apply_btn = btn
|
|
logger.info(f"[GESOBAU] Found visible button with selector '{sel}'")
|
|
break
|
|
except Exception as e:
|
|
logger.warning(f"[GESOBAU] Error checking button visibility: {e}")
|
|
if apply_btn:
|
|
break
|
|
|
|
if apply_btn:
|
|
logger.info("[GESOBAU] Found application button, scrolling into view...")
|
|
await apply_btn.scroll_into_view_if_needed()
|
|
await asyncio.sleep(0.5)
|
|
logger.info("[GESOBAU] Clicking button...")
|
|
await apply_btn.click()
|
|
await asyncio.sleep(2)
|
|
result["success"] = True
|
|
result["message"] = "Application submitted successfully."
|
|
else:
|
|
result["message"] = "No application button found."
|
|
except Exception as e:
|
|
result["message"] = f"Error during application: {e}"
|
|
logger.error(f"[GESOBAU] Application error: {e}")
|
|
finally:
|
|
await page.close()
|
|
|
|
return result |