From 4c98fee285e6337a9ae598148d37f84f6e24a279 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 29 Nov 2025 23:52:10 +0000 Subject: [PATCH] fix: Skip strikethrough prices to avoid detecting old/crossed-out prices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Problem:** AI was detecting old crossed-out prices instead of current prices. Example: Stokomani Lutin - Current: 19,99€, Old (strikethrough): 14,99€ AI detected: 14.99 EUR (wrong - old price) **Root Cause:** Generic price extraction was finding ALL price elements without checking if they were visually crossed-out (text-decoration: line-through). Many e-commerce sites show: ```html 14,99 € 19,99 € ``` The selector finds both, but we were returning the first found. **Solution: Check CSS text-decoration** Added strikethrough detection (browserless_service.py:182-189): ```python # Check if element is strikethrough (old price) text_decoration = await element.evaluate( "el => window.getComputedStyle(el).textDecoration" ) if "line-through" in text_decoration: continue # Skip crossed-out prices ``` **Flow:** ``` Found elements with .price selector: [elem1, elem2, elem3] ↓ For each element: 1. Check visibility ✓ 2. Check text-decoration → "line-through" → SKIP ✓ → "none" → CONTINUE 3. Extract price text ↓ Return first non-strikethrough price ``` **CSS Patterns Detected:** - `text-decoration: line-through` (most common) - `text-decoration: line-through solid` - Combined styles ignored if they don't contain "line-through" **Expected Results:** - Before: Returns first price found (14.99 if it's first in DOM) - After: Skips strikethrough prices, returns current price (19.99) **Note:** Existing selector already excludes common classes: `:not([class*='old']):not([class*='was']):not([class*='original'])` This adds runtime CSS check as additional safety layer. Partial fix for Stokomani Lutin 14.99 vs 19.99 issue. May need site-specific selectors if problem persists. --- app/services/browserless_service.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/services/browserless_service.py b/app/services/browserless_service.py index 708a4b1..7a6cb51 100644 --- a/app/services/browserless_service.py +++ b/app/services/browserless_service.py @@ -179,6 +179,15 @@ class BrowserlessService: try: element = elements.nth(i) if await element.is_visible(timeout=1000): + # Check if element is strikethrough (old price) + try: + text_decoration = await element.evaluate("el => window.getComputedStyle(el).textDecoration") + if "line-through" in text_decoration: + logger.debug(f"Skipping strikethrough price at {selector}") + continue # Skip crossed-out prices + except Exception: + pass # If we can't check, continue anyway + price_text = await element.inner_text() # Check if it looks like a price (contains € or digits with comma/dot) if price_text and ('€' in price_text or (',' in price_text and any(c.isdigit() for c in price_text))):