try click endpoint
Build and Push Docker Images / build-and-push (push) Successful in 1m17s

This commit is contained in:
2026-03-30 10:06:11 +02:00
parent 6b2c06d8fd
commit df44afeaff
24 changed files with 94 additions and 0 deletions
@@ -119,6 +119,62 @@ async def screenshot_url_service(decoded_url, full_page=True):
return await safe_browser_operation(decoded_url, screenshot_operation)
async def click_selector_service(decoded_url: str, selector: str, return_type: str):
"""Navigate to a URL, click a CSS selector, and return PNG bytes or resulting HTML."""
print(f"Clicking selector on {decoded_url}: {selector}")
async def click_operation(page):
try:
# Navigate and wait for initial DOM.
await page.goto(decoded_url, wait_until='domcontentloaded', timeout=30000)
await page.wait_for_load_state('load', timeout=30000)
# Ensure the page is fully loaded (helps with JS-driven UIs).
await page.wait_for_function("document.readyState === 'complete'", timeout=30000)
# Best-effort cookie banner handling (helps avoid click interception).
cookie_buttons = [
'Accept all',
'Accepteer',
'Accepteren',
'Accept'
]
for button in cookie_buttons:
try:
element = await page.query_selector(f'text="{button}"')
if element:
await element.click()
await page.wait_for_timeout(1000)
break
except Exception:
# Ignore cookie/banner interaction errors; click may still work.
pass
# Wait for the target selector, scroll it into view, then click.
await page.wait_for_selector(selector, timeout=30000)
locator = page.locator(selector)
await locator.scroll_into_view_if_needed(timeout=30000)
await locator.click(force=True, timeout=30000)
# Give the page a moment to react to the click.
await page.wait_for_timeout(1000)
try:
await page.wait_for_load_state('networkidle', timeout=10000)
except Exception:
pass
if return_type == "html":
return await page.content()
# Return a full-page screenshot of the resulting view.
return await page.screenshot(full_page=True, type='png')
except Exception as e:
print(f"Error during click capture: {e}")
return {"status": "error", "url": decoded_url, "error": str(e)}
return await safe_browser_operation(decoded_url, click_operation)
async def extract_seo_service(decoded_url):
"""Service function to extract SEO information from a website"""
print(f"Extracting SEO from: {decoded_url}")