Files
Priceflow/app
Claude 1c763143ca feat: Improve price extraction with priority selectors and smart multi-price handling
**Problem:**
Stokomani Lutin product detected 14.99 EUR instead of 19.99 EUR.
Website shows both old price (14.99) and current price (19.99).
Generic extraction was returning whichever price was found first.

**Root Causes:**
1. No prioritization of price selectors (all treated equally)
2. First-found-first-returned approach missed semantic selectors
3. When multiple prices found, no logic to select the correct one

**Solution: Priority-Based Extraction + Smart Selection**

1. **Reordered Selectors by Priority** (browserless_service.py:151-170)
   ```
   HIGHEST PRIORITY (return immediately):
   - [itemprop='price']    (Schema.org semantic)
   - .current-price        (explicit current)
   - .sale-price           (sale/promo price)
   - .final-price          (final calculated)
   - .product-price        (product-specific)

   MEDIUM PRIORITY:
   - [class*='price']:not([class*='old']):not([class*='was'])...
   - Excludes: old, was, original, before, regular, ancien, barre

   LOW PRIORITY:
   - .price (generic, might catch anything)
   ```

2. **Immediate Return for High-Priority Selectors** (lines 202-204)
   - If found with semantic selector → return immediately
   - Avoids checking lower-priority selectors
   - Most reliable prices checked first

3. **Multi-Price Smart Selection** (lines 210-218)
   - If multiple prices found (e.g., old + current)
   - Takes LAST price in DOM order (not highest/lowest value)
   - Rationale: HTML structure typically shows old price first, current price last:
     ```html
     <span class="old-price">14,99 €</span>  ← First in DOM
     <span class="price">19,99 €</span>      ← Last in DOM (CURRENT)
     ```
   - Logs all found prices for debugging

**Why Not "Highest Price"?**
Taking highest value fails in promotions:
```
Old: 29,99 € (highest)
Current: 19,99 € (promotion) ← Should select this
```
Taking last in DOM works for both cases:
```
Case 1 (Stokomani):
  Old: 14,99 € (first)
  Current: 19,99 € (last) ← Selected ✓

Case 2 (Promotion):
  Old: 29,99 € (first)
  Current: 19,99 € (last) ← Selected ✓
```

**Flow:**
```
Search for [itemprop='price']
  → Found? Return immediately ✓
  → Not found? Continue...
Search for .current-price
  → Found? Return immediately ✓
  → Not found? Continue...
...
Search with low-priority selectors
  → Found: ["14,99 €", "19,99 €"]
  → Select last: "19,99 €" ✓
```

**Expected Results:**
- Before: "14.99 EUR" (first found, wrong)
- After: "19.99 EUR" (last in DOM, correct)
- Logs: "Multiple prices found: ['14,99 €', '19,99 €'], selecting last: 19,99 €"

Tested with: https://www.stokomani.fr/products/lutin-filou-telescopique-95-cm_208400
2025-11-29 23:55:05 +00:00
..
2025-11-22 10:01:25 +01:00
2025-11-22 10:01:25 +01:00
2025-11-22 10:01:25 +01:00
2025-11-22 10:01:25 +01:00