major refactor (untested)
This commit is contained in:
parent
a29412b4da
commit
a77a0c0393
22 changed files with 1037 additions and 24 deletions
59
handlers/degewo_handler.py
Normal file
59
handlers/degewo_handler.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
from .base_handler import BaseHandler
|
||||
import logging
|
||||
import asyncio
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class DegewoHandler(BaseHandler):
|
||||
async def apply(self, listing: dict, result: dict) -> dict:
|
||||
page = await self.context.new_page()
|
||||
try:
|
||||
logger.info(f"[DEGEWO] Opening page: {listing['link']}")
|
||||
await page.goto(listing["link"], wait_until="networkidle")
|
||||
logger.info("[DEGEWO] 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("[DEGEWO] 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"[DEGEWO] Selector '{sel}' found {len(all_btns)} matches")
|
||||
for btn in all_btns:
|
||||
try:
|
||||
if await btn.is_visible():
|
||||
apply_btn = btn
|
||||
logger.info(f"[DEGEWO] Found visible button with selector '{sel}'")
|
||||
break
|
||||
except Exception as e:
|
||||
logger.warning(f"[DEGEWO] Error checking button visibility: {e}")
|
||||
if apply_btn:
|
||||
break
|
||||
|
||||
if apply_btn:
|
||||
logger.info("[DEGEWO] Found application button, scrolling into view...")
|
||||
await apply_btn.scroll_into_view_if_needed()
|
||||
await asyncio.sleep(0.5)
|
||||
logger.info("[DEGEWO] 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"[DEGEWO] Application error: {e}")
|
||||
finally:
|
||||
await page.close()
|
||||
|
||||
return result
|
||||
Loading…
Add table
Add a link
Reference in a new issue