roughly working again, now dev docker exists
This commit is contained in:
parent
a77a0c0393
commit
155ab39368
26 changed files with 1976 additions and 235 deletions
|
|
@ -5,50 +5,76 @@ import asyncio
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
class DegewoHandler(BaseHandler):
|
||||
def __init__(self, browser_context):
|
||||
self.context = browser_context
|
||||
|
||||
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")
|
||||
logger.info(f"[DEGEWO] Open: {listing['link']}")
|
||||
response = await page.goto(listing["link"], wait_until="networkidle")
|
||||
await asyncio.sleep(2)
|
||||
|
||||
# Handle cookies and consent
|
||||
# Detect 404 by status or page title
|
||||
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"[DEGEWO] 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
|
||||
return result
|
||||
|
||||
# Always handle cookies and consent before anything else
|
||||
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")'
|
||||
]
|
||||
# Save HTML after modal handling for debugging
|
||||
try:
|
||||
html_content = await page.content()
|
||||
with open("data/degewo_debug.html", "w", encoding="utf-8") as f:
|
||||
f.write(html_content)
|
||||
except Exception as e:
|
||||
logger.debug(f"[DEGEWO] Debug HTML not saved: {e}")
|
||||
|
||||
logger.info("[DEGEWO] Searching for application button...")
|
||||
selectors = [
|
||||
'a.btn',
|
||||
'button.btn',
|
||||
'a:has-text("Bewerben")',
|
||||
'button:has-text("Bewerben")',
|
||||
'a:has-text("Anfrage")',
|
||||
'button:has-text("Anfrage")',
|
||||
'a:has-text("Kontakt")',
|
||||
'button:has-text("Kontakt")',
|
||||
]
|
||||
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")
|
||||
logger.debug(f"[DEGEWO] Selector '{sel}': {len(all_btns)} matches")
|
||||
for btn in all_btns:
|
||||
try:
|
||||
if await btn.is_visible():
|
||||
btn_text = (await btn.inner_text()).lower()
|
||||
if any(x in btn_text for x in ["drucken", "merken", "zurück"]):
|
||||
continue
|
||||
apply_btn = btn
|
||||
logger.info(f"[DEGEWO] Found visible button with selector '{sel}'")
|
||||
logger.info(f"[DEGEWO] Found visible application button: {sel} [{btn_text}]")
|
||||
break
|
||||
except Exception as e:
|
||||
logger.warning(f"[DEGEWO] Error checking button visibility: {e}")
|
||||
logger.debug(f"[DEGEWO] Button visibility error: {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:
|
||||
logger.warning("[DEGEWO] No application button found.")
|
||||
result["message"] = "No application button found."
|
||||
except Exception as e:
|
||||
result["message"] = f"Error during application: {e}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue