mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-15 03:06:54 +02:00
**Problem:**
Price extraction was only working for Amazon. Other sites (B&M, Stokomani, etc.)
had prices missing from extracted text, causing AI to rely solely on screenshots.
Example error:
```
WARNING - No prices found in text with € symbol
AI Response: {"price": 9.99} // Wrong! Real price was 1.99€
```
**Root Cause:**
- `page.inner_text('body')` doesn't capture all price elements
- Some sites use hidden elements, iframes, or CSS pseudo-elements
- Only Amazon had dedicated price extraction (_extract_amazon_price)
- Other sites got: `WARNING - Could not extract price from DOM`
**Solution: Universal Price Extraction**
1. **New Method: _extract_generic_price()** (browserless_service.py:145-208)
- Tries common CSS selectors across all e-commerce sites:
* Class-based: `.price`, `.product-price`, `.current-price`
* Attribute-based: `[data-price]`, `[itemprop='price']`
* French-specific: `[class*='prix']`, `[class*='tarif']`
* Excludes old prices: `:not([class*='old'])`
- Validates price format (contains € or comma with digits)
- Falls back to regex: `\d+[,\.]\d{2}\s*€` on all text
- Returns first valid price found
2. **Updated Extraction Logic** (browserless_service.py:319-338)
- Amazon → uses `_extract_amazon_price()` (specific)
- All other sites → uses `_extract_generic_price()` (universal)
- Prepends "PRIX DÉTECTÉ: X,XX €" to text context
- Logs success/failure for debugging
**Flow:**
```
Page load (bmstores.fr)
↓
Try selectors: .price, .product-price, [itemprop='price']...
↓
Found: "1,99 €" via selector .price
↓
Prepend: "PRIX DÉTECTÉ: 1,99 €\n\n[page text]"
↓
Send to AI
↓
AI sees explicit price → {"price": 1.99, "confidence": 0.95}
```
**Expected Results:**
- Before: `WARNING - No prices found in text with € symbol`
- After: `INFO - Found price via selector .price: 1,99 €`
- AI confidence improves (text + image vs image only)
- Fewer digit recognition errors (1 vs 9)
**Tested with:**
- https://bmstores.fr/produits/accessoire-noel-enfant/125651-lutin-farceur-35cm
- Price: 1,99 €
Fixes issue where non-Amazon sites had missing prices in text context,
causing AI to misread prices from screenshots only.