notebook
This commit is contained in:
@@ -72,6 +72,15 @@ def wait_load(page, extra_ms=1000):
|
||||
|
||||
def dbg(page, label):
|
||||
print(f"[{label}] URL: {page.url}")
|
||||
try:
|
||||
from pathlib import Path
|
||||
shots = Path(__file__).parent / "debug_shots"
|
||||
shots.mkdir(exist_ok=True)
|
||||
path = shots / f"{label}.png"
|
||||
page.screenshot(path=str(path), full_page=True)
|
||||
print(f"[{label}] screenshot: {path}")
|
||||
except Exception as e:
|
||||
print(f"[{label}] screenshot failed: {e}")
|
||||
|
||||
|
||||
def extract_study_label(study_search: str) -> str:
|
||||
@@ -178,16 +187,32 @@ def select_role(page):
|
||||
print(f" Vybráno: '{txt}'")
|
||||
break
|
||||
|
||||
clicked = False
|
||||
for btn_sel in ['input[value="Continue"]', 'input[type="submit"]',
|
||||
'button:has-text("Continue")', 'button[type="submit"]']:
|
||||
try:
|
||||
btn = page.query_selector(btn_sel)
|
||||
except Exception:
|
||||
break
|
||||
continue
|
||||
if btn:
|
||||
btn.click()
|
||||
wait_load(page, 2000)
|
||||
break
|
||||
try:
|
||||
with page.expect_navigation(timeout=15_000):
|
||||
btn.click()
|
||||
clicked = True
|
||||
break
|
||||
except PWTimeout:
|
||||
print(f" Click on {btn_sel} nezpůsobil navigaci, zkouším další...")
|
||||
continue
|
||||
|
||||
if not clicked:
|
||||
print(" Fallback: submituji formulář přes JS...")
|
||||
try:
|
||||
with page.expect_navigation(timeout=15_000):
|
||||
page.evaluate("document.forms[0] && document.forms[0].submit()")
|
||||
except PWTimeout:
|
||||
print(" JS submit fallback také neprošel.")
|
||||
|
||||
wait_load(page, 1500)
|
||||
dbg(page, "after-role")
|
||||
|
||||
|
||||
@@ -404,8 +429,12 @@ def download_datalisting(study: str, forms: list[str], country: str | None = Non
|
||||
results = []
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=False, slow_mo=200)
|
||||
ctx_kwargs = {"accept_downloads": True}
|
||||
browser = p.chromium.launch(
|
||||
headless=False,
|
||||
slow_mo=200,
|
||||
args=["--start-maximized"],
|
||||
)
|
||||
ctx_kwargs = {"accept_downloads": True, "no_viewport": True}
|
||||
|
||||
use_saved = auth_valid()
|
||||
if use_saved:
|
||||
|
||||
Reference in New Issue
Block a user