mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-24 07:38:13 +02:00
Fix: Deep fix for Action.com availability false positives. Advanced title normalization and clarified unavailability detection logic. Optimized ActionParser.
This commit is contained in:
1 parent
8329eb28a3
commit
4a686e1b86
3 files changed
+74
-36
No files matched your search
@@ -1,9 +1,11 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from app.services.parsers.base_parser import BaseParser, ProductResult
|
||||
import logging
|
||||
import re
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ActionParser(BaseParser):
|
||||
def __init__(self):
|
||||
super().__init__("action.com", "https://www.action.com")
|
||||
@@ -11,55 +13,62 @@ class ActionParser(BaseParser):
|
||||
def parse_search_results(self, html: str, query: str, search_url: str) -> list[ProductResult]:
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
results = []
|
||||
|
||||
|
||||
# Action products
|
||||
# Config: a.group[href^='/fr-fr/p/']
|
||||
|
||||
|
||||
links = soup.select("a[href^='/fr-fr/p/']")
|
||||
|
||||
|
||||
seen_urls = set()
|
||||
|
||||
|
||||
for link in links:
|
||||
try:
|
||||
href = link.get('href')
|
||||
href = link.get("href")
|
||||
if not href or href in seen_urls:
|
||||
continue
|
||||
seen_urls.add(href)
|
||||
|
||||
|
||||
url = self.make_absolute_url(href)
|
||||
|
||||
|
||||
# Action usually has the card content inside the link
|
||||
title = None
|
||||
title_el = link.select_one("[class*='title'], h3, h4")
|
||||
if title_el:
|
||||
title = title_el.get_text(strip=True)
|
||||
else:
|
||||
title = link.get_text(strip=True)
|
||||
|
||||
# Fallback to specific spans or remove price info from text
|
||||
# Often Action cards have a .title span
|
||||
title = link.get_text(" ", strip=True)
|
||||
# Remove price-like patterns from title if we had to get whole link text
|
||||
title = re.sub(r"\d+,\d+\s*€.*$", "", title)
|
||||
title = re.sub(r"\d+\s*€.*$", "", title)
|
||||
|
||||
if not title:
|
||||
continue
|
||||
|
||||
img_url = self.extract_image_url(link)
|
||||
|
||||
|
||||
price = None
|
||||
price_el = link.select_one("[class*='price']")
|
||||
if price_el:
|
||||
price = self.parse_price_text(price_el.get_text())
|
||||
|
||||
results.append(ProductResult(
|
||||
title=title,
|
||||
url=url,
|
||||
source="Action",
|
||||
price=price,
|
||||
currency="EUR",
|
||||
in_stock=True,
|
||||
image_url=img_url,
|
||||
snippet=f"Product from Action"
|
||||
))
|
||||
|
||||
|
||||
results.append(
|
||||
ProductResult(
|
||||
title=title,
|
||||
url=url,
|
||||
source="Action",
|
||||
price=price,
|
||||
currency="EUR",
|
||||
in_stock=True,
|
||||
image_url=img_url,
|
||||
snippet=f"Product from Action",
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error parsing Action product: {e}")
|
||||
continue
|
||||
|
||||
|
||||
logger.info(f"ActionParser found {len(results)} results")
|
||||
return results
|
||||
Reference in new issue
Block a user