add debug option

This commit is contained in:
2026-02-07 15:35:09 +01:00
parent 57f32dcce5
commit 3478d8abbe
8 changed files with 32 additions and 5 deletions

View File

@@ -153,6 +153,8 @@ def main() -> None:
max_tests = int(os.getenv("SCRAPE_TEST_MAX", "0"))
headful_on_block = os.getenv("SCRAPE_TEST_HEADFUL_ON_BLOCK", "0") == "1"
wait_on_block = int(os.getenv("SCRAPE_TEST_WAIT_ON_BLOCK", "60"))
# Permet de forcer le debug en tests même si désactivé dans config
debug_enabled = os.getenv("SCRAPE_TEST_DEBUG_ENABLED", str(config.scrape.debug_enabled)).lower() in ("1", "true")
results = []
with sync_playwright() as playwright:
@@ -186,7 +188,9 @@ def main() -> None:
logger.info("Scraping {} ({})", test_id, url)
page.goto(url, wait_until="domcontentloaded", timeout=config.scrape.timeout_ms)
debug_files = save_debug_artifacts(page, test_id, "capture")
debug_files = {}
if debug_enabled:
debug_files = save_debug_artifacts(page, test_id, "capture")
data = extract_product_data(page, url)
if not data.get("titre"):
logger.warning("Titre absent, suspicion de blocage pour {}", test_id)
@@ -197,7 +201,8 @@ def main() -> None:
manual_context = manual_browser.new_context(**manual_context_kwargs)
manual_page = manual_context.new_page()
manual_page.goto(url, wait_until="domcontentloaded", timeout=config.scrape.timeout_ms)
save_debug_artifacts(manual_page, test_id, "manual")
if debug_enabled:
save_debug_artifacts(manual_page, test_id, "manual")
logger.info("Résoudre le captcha puis appuyer sur Entrée.")
try:
input()