mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-11 17:29:14 +02:00
feat: implement improved search service with persistent browser connection and update search verification script.
This commit is contained in:
1 parent
39d4107e6d
commit
48f149d38f
2 files changed
+2
-22
No files matched your search
@@ -409,26 +409,6 @@ class ImprovedSearchService:
|
||||
async def _scrape_item_details(cls, result: SearchResult, context: BrowserContext) -> SearchResult | None:
|
||||
"""Scrape price and details for a single item using same context"""
|
||||
try:
|
||||
# SPECIAL CASE: L'Incroyable - Price is in the title
|
||||
if "lincroyable.fr" in result.url:
|
||||
import re
|
||||
|
||||
# Extract price from title (e.g., "34€99" or "59€99")
|
||||
# Extract price from title (e.g., "34€99" or "59€99")
|
||||
# Fix: Use non-greedy regex and ensure only 2 decimals
|
||||
price_match = re.search(r"(\d+)€(\d{2})(?!\d)", result.title)
|
||||
if price_match:
|
||||
# Convert to float (e.g., "34€99" -> 34.99)
|
||||
price_euros = int(price_match.group(1))
|
||||
price_cents = int(price_match.group(2))
|
||||
result.price = float(f"{price_euros}.{price_cents}")
|
||||
|
||||
# Clean title by removing price
|
||||
result.title = re.sub(r"\d+€\d+", "", result.title).strip()
|
||||
logger.debug(f"L'Incroyable - Extracted price {result.price}€ from title")
|
||||
|
||||
return result
|
||||
|
||||
# SPECIAL CASE: Gifi - Price extracted from search, no need to visit page
|
||||
if "gifi.fr" in result.url and result.price is not None:
|
||||
logger.debug(f"Gifi - Price already extracted from search: {result.price}€")
|
||||
|
||||
@@ -30,8 +30,8 @@ ImprovedSearchService._connect_browser = _connect_browser_local
|
||||
async def test_search():
|
||||
await ImprovedSearchService.initialize()
|
||||
|
||||
query = "Mange-debout" # Common item on their site
|
||||
target_site = "lincroyable.fr"
|
||||
query = "nintendo switch"
|
||||
target_site = "gifi.fr"
|
||||
|
||||
print(f"Searching for: {query} on {target_site}")
|
||||
|
||||
|
||||
Reference in new issue
Block a user