fix: Skip strikethrough prices to avoid detecting old/crossed-out prices

**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
<span class="old-price" style="text-decoration: line-through">14,99 €</span>
<span class="price">19,99 €</span>
```
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.
This commit is contained in:
Claude committed 2025-11-29 23:52:10 +00:00
1 parent 531ed1bc15
commit 4c98fee285
1 file changed
+9
+9
View File
@@ -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))):