From 844c75f1904a27c8c701a73b9b98e2e977ebcfd6 Mon Sep 17 00:00:00 2001 From: R0m1k3 Date: Fri, 30 Jan 2026 14:53:48 +0100 Subject: [PATCH] feat: Add initial search configuration for e-commerce sites and a tracking scraper service. --- app/core/search_config.py | 4 ++-- app/services/tracking_scraper_service.py | 28 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/core/search_config.py b/app/core/search_config.py index d8ce6c2..46981c1 100644 --- a/app/core/search_config.py +++ b/app/core/search_config.py @@ -198,10 +198,10 @@ SITE_CONFIGS = { "search_url": "https://www.action.com/fr-fr/search/?q={query}", "product_selector": "div[data-testid='product-card']", "product_image_selector": "img[data-testid='product-card-image']", - "price_selector": ".product-price, [data-testid='product-price'], .price", + "price_selector": ".product-price, [data-testid='product-price'], .price, .current-price, .product-card__price", "wait_selector": "div[data-testid='product-card']", "category": "Discount", - "requires_proxy": True, + "requires_proxy": False, }, "e-leclerc.com": { "name": "E.Leclerc", diff --git a/app/services/tracking_scraper_service.py b/app/services/tracking_scraper_service.py index ce20f45..e1239e4 100644 --- a/app/services/tracking_scraper_service.py +++ b/app/services/tracking_scraper_service.py @@ -191,9 +191,9 @@ class ScraperService: logger.info(f"Using configured price selector for {domain}: {config_selector}") selector = config_selector - # Special override: If Action.com, force proxy - if "action.com" in domain: - requires_proxy = True + # Special override: If Action.com, force proxy ONLY if strictly needed and proxies are available + # if "action.com" in domain: + # requires_proxy = True proxy = None if requires_proxy: @@ -208,6 +208,10 @@ class ScraperService: if "amazon" in url: return await ScraperService._scrape_amazon_specific(url, item_id, config, return_html, proxy) + # SPECIALIZED ACTION HANDLING (Rupture de stock check) + is_action = "action.com" in url + + context = await ScraperService._create_context(ScraperService._browser, url, proxy=proxy) page = await context.new_page() @@ -698,6 +702,24 @@ class ScraperService: } """) + # Extra cleanup to prevent TitlePrice merging + # If we are on Action, we might need specific spacing logic + if "action.com" in page.url: + clean_text = await page.evaluate(""" + () => { + const title = document.querySelector('h1, .product-title'); + const price = document.querySelector('.price, .product-price'); + + let text = document.body.innerText; + + // Manually construct clean string if elements found + if(title && price) { + return title.innerText + " " + price.innerText + "\\n" + text; + } + return text; + } + """) + # Fallback if cleaning removed everything (unlikely but safe) if not clean_text or len(clean_text) < 100: logger.warning("Cleaned text too short, falling back to full body text")