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