major refactor (untested)
This commit is contained in:
parent
a29412b4da
commit
a77a0c0393
22 changed files with 1037 additions and 24 deletions
42
handlers/base_handler.py
Normal file
42
handlers/base_handler.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from playwright.async_api import Page
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class BaseHandler(ABC):
|
||||
def __init__(self, context):
|
||||
self.context = context
|
||||
|
||||
@abstractmethod
|
||||
async def apply(self, listing: dict, result: dict) -> dict:
|
||||
"""Abstract method to handle the application process for a specific company."""
|
||||
pass
|
||||
|
||||
async def handle_cookies(self, page: Page):
|
||||
"""Handle cookie banners if present."""
|
||||
try:
|
||||
cookie_btn = await page.query_selector('button:has-text("Akzeptieren"), button:has-text("Alle akzeptieren")')
|
||||
if cookie_btn and await cookie_btn.is_visible():
|
||||
await cookie_btn.click()
|
||||
logger.info("[BaseHandler] Dismissed cookie banner")
|
||||
await asyncio.sleep(1)
|
||||
except Exception as e:
|
||||
logger.warning(f"[BaseHandler] Failed to handle cookies: {e}")
|
||||
|
||||
async def handle_consent(self, page: Page):
|
||||
"""Handle consent manager banners if present."""
|
||||
try:
|
||||
consent_selectors = [
|
||||
'#cmpbntyestxt', '.cmpboxbtnyes', 'a.cmpboxbtn.cmpboxbtnyes',
|
||||
'#cmpwelcomebtnyes', '.cmptxt_btn_yes'
|
||||
]
|
||||
for sel in consent_selectors:
|
||||
consent_btn = await page.query_selector(sel)
|
||||
if consent_btn and await consent_btn.is_visible():
|
||||
await consent_btn.click()
|
||||
logger.info("[BaseHandler] Dismissed consent manager")
|
||||
await asyncio.sleep(1)
|
||||
break
|
||||
except Exception as e:
|
||||
logger.warning(f"[BaseHandler] Failed to handle consent manager: {e}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue