From b47af1655da1eae4bd1392288363c22e5b44685b Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Sat, 29 Nov 2025 17:46:20 +0100 Subject: [PATCH] feat: add debug script to display search site configurations and database entries --- analyze_missing_sites.py | 93 +++++++++++++++++++++++++++++++++++++++ app/core/search_config.py | 25 +++++++++++ debug_sites.py | 30 +++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 analyze_missing_sites.py create mode 100644 debug_sites.py diff --git a/analyze_missing_sites.py b/analyze_missing_sites.py new file mode 100644 index 0000000..fa7eca5 --- /dev/null +++ b/analyze_missing_sites.py @@ -0,0 +1,93 @@ +""" +Script pour analyser les sélecteurs CSS des sites manquants +""" +import asyncio +from playwright.async_api import async_playwright + +async def analyze_site(url: str, site_name: str): + print(f"\n=== Analyse de {site_name} ===") + print(f"URL: {url}") + + async with async_playwright() as p: + browser = await p.chromium.launch(headless=False) + page = await browser.new_page() + + try: + await page.goto(url, wait_until="networkidle", timeout=30000) + await page.wait_for_timeout(3000) + + # Try cookie banners + cookie_selectors = [ + "button:has-text('Accepter')", + "button:has-text('Tout accepter')", + "#didomi-notice-agree-button", + ".didomi-continue-without-agreeing" + ] + for selector in cookie_selectors: + try: + await page.click(selector, timeout=2000) + print(f"✓ Cookie banner fermé: {selector}") + break + except: + pass + + await page.wait_for_timeout(2000) + + # Save HTML + html = await page.content() + filename = f"{site_name.lower().replace(' ', '_')}_search.html" + with open(filename, "w", encoding="utf-8") as f: + f.write(html) + print(f"✓ HTML sauvegardé: {filename}") + + # Take screenshot + screenshot_path = f"{site_name.lower().replace(' ', '_')}_search.png" + await page.screenshot(path=screenshot_path, full_page=True) + print(f"✓ Screenshot: {screenshot_path}") + + # Test common product link selectors + test_selectors = [ + "a.product-link", + "a.product-name", + "a[href*='/produit']", + "a[href*='/product']", + "a[href*='/p/']", + ".product-title a", + ".product-item a", + "article a", + "a.product", + "a[itemprop='url']", + ] + + print("\n--- Test de sélecteurs ---") + for selector in test_selectors: + try: + elements = await page.query_selector_all(selector) + if elements: + print(f"✓ {selector}: {len(elements)} éléments trouvés") + # Get first few hrefs + for i, elem in enumerate(elements[:3]): + href = await elem.get_attribute("href") + text = await elem.inner_text() + print(f" [{i+1}] {text[:50]} -> {href}") + except Exception as e: + pass + + except Exception as e: + print(f"❌ Erreur: {e}") + finally: + await browser.close() + +async def main(): + sites = [ + ("https://bmstores.fr/module/ambjolisearch/jolisearch?s=chaise", "BM"), + ("https://www.centrakor.com/recherche?controller=search&s=chaise", "Centrakor"), + ("https://www.lincroyable.fr/recherche?query=chaise", "L'Incroyable"), + ] + + for url, name in sites: + await analyze_site(url, name) + await asyncio.sleep(2) + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/app/core/search_config.py b/app/core/search_config.py index 7fc6450..3be93a0 100644 --- a/app/core/search_config.py +++ b/app/core/search_config.py @@ -119,6 +119,31 @@ SITE_CONFIGS = { "category": "Culture & Tech", "requires_proxy": False, }, + # === NOUVEAUX SITES === + "bmstores.fr": { + "name": "B&M", + "search_url": "https://bmstores.fr/module/ambjolisearch/jolisearch?s={query}", + "product_selector": "a.thumbnail.product-thumbnail", + "wait_selector": ".products, .product-miniature", + "category": "Discount", + "requires_proxy": False, + }, + "centrakor.com": { + "name": "Centrakor", + "search_url": "https://www.centrakor.com/search/{query}", + "product_selector": "a.link.link--block", + "wait_selector": ".product-list, .product-item", + "category": "Discount", + "requires_proxy": False, + }, + "lincroyable.fr": { + "name": "L'Incroyable", + "search_url": "https://www.lincroyable.fr/recherche-query={query}/", + "product_selector": "a[href*='.html']", + "wait_selector": ".product-item, .product-list", + "category": "Discount", + "requires_proxy": False, + }, } # === COOKIE BANNERS === diff --git a/debug_sites.py b/debug_sites.py new file mode 100644 index 0000000..4b45bcc --- /dev/null +++ b/debug_sites.py @@ -0,0 +1,30 @@ +import sys +import os + +# Add app to path +sys.path.append(os.getcwd()) + +from app.core.database import SessionLocal +from app.models import SearchSite +from app.core.search_config import SITE_CONFIGS + +def debug_sites(): + db = SessionLocal() + try: + print("=== SITE_CONFIGS Keys ===") + for key in SITE_CONFIGS.keys(): + print(f"- {key}") + + print("\n=== DB SearchSites ===") + sites = db.query(SearchSite).all() + for site in sites: + print(f"ID: {site.id} | Name: {site.name} | Domain: {site.domain} | Active: {site.is_active}") + print(f" URL: {site.search_url}") + print(f" Selector: {site.product_link_selector}") + print("-" * 20) + + finally: + db.close() + +if __name__ == "__main__": + debug_sites()