fix(scraper): improve navigation and click reliability for export [32788f42]

This commit is contained in:
2026-03-20 19:53:00 +00:00
parent 5294d73dc1
commit fa65e99310

View File

@@ -317,32 +317,43 @@ async def generate_pdf(job_id: str, account_type: str):
if not login(driver, username, password):
raise HTTPException(status_code=401, detail="Login failed.")
# 1. Navigate to names list page (where the export button lives)
reg_url = f"https://app.fotograf.de/config_children/view_names_list/{job_id}"
logger.info(f"Navigating to names list (Personen): {reg_url}")
driver.get(reg_url)
# 1. Navigate to job settings page first
job_url = f"https://app.fotograf.de/config_jobs_settings/index/{job_id}"
logger.info(f"Navigating to job main page: {job_url}")
driver.get(job_url)
wait = WebDriverWait(driver, 30)
# Get Institution Name for PDF
try:
institution = driver.find_element(By.TAG_NAME, "h1").text.strip()
logger.debug(f"Detected institution name: {institution}")
except:
institution = "Fotoauftrag"
logger.info("Triggering CSV Export...")
export_btn = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, SELECTORS["export_dropdown"])))
export_btn.click()
# 1.5 Click on the "Personen" tab
logger.info("Clicking on 'Personen' tab...")
personen_tab = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[data-qa-id='link:photo-jobs-tabs-names_list']")))
personen_tab.click()
# Wait for the export button to become present on the new tab
logger.info("Waiting for Export Dropdown...")
export_btn = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, SELECTORS["export_dropdown"]))))
# Scroll to it and click via JS to avoid obscuring elements
driver.execute_script("arguments[0].scrollIntoView(true);", export_btn)
time.sleep(1) # small pause after scroll
logger.info("Clicking Export Dropdown...")
driver.execute_script("arguments[0].click();", export_btn)
logger.debug("Export dropdown clicked, waiting for menu items...")
time.sleep(2)
try:
csv_btn = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, SELECTORS["export_csv_link"])))
csv_btn.click()
logger.info("CSV Export button clicked.")
csv_btn = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, SELECTORS["export_csv_link"]))))
logger.info("CSV Export button found. Clicking...")
driver.execute_script("arguments[0].click();", csv_btn)
except TimeoutException:
logger.error("CSV Button not found after clicking dropdown.")
take_error_screenshot(driver, "csv_button_missing")
raise HTTPException(status_code=500, detail="CSV Export Button konnte nicht gefunden werden.")
# Wait for file to appear
logger.debug("Waiting for CSV file in download directory...")