mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-24 07:38:13 +02:00
feat: Implement new product parsers for Stokomani, Auchan, Carrefour, and Gifi, and add a centralized search configuration module.
This commit is contained in:
1 parent
e0d73f4d0e
commit
b44082aeb4
5 files changed
+75
-50
No files matched your search
@@ -12,55 +12,70 @@ class AuchanParser(BaseParser):
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
results = []
|
||||
|
||||
# Auchan products
|
||||
# Config: article, div[class*='product-card']
|
||||
# Auchan products - Ultra Robust Strategy
|
||||
# The DOM is flat and dynamic. We rely on finding product links first.
|
||||
# Links usually contain '/p-' in the href.
|
||||
|
||||
cards = soup.select("article, div[class*='product-card'], div[class*='list__item']")
|
||||
links = soup.select("a[href*='/p-']")
|
||||
seen_urls = set()
|
||||
|
||||
# Fallback: try finding links directly
|
||||
if not cards:
|
||||
links = soup.select("a[href*='/p-']")
|
||||
cards = []
|
||||
for link in links:
|
||||
parent = link.find_parent("article") or link.find_parent("div", class_=lambda x: x and "product" in x)
|
||||
if parent:
|
||||
cards.append(parent)
|
||||
else:
|
||||
cards.append(link.parent)
|
||||
|
||||
for card in cards:
|
||||
for link in links:
|
||||
try:
|
||||
link_el = card.select_one("a[href*='/p-'], a")
|
||||
if not link_el:
|
||||
href = link.get('href')
|
||||
if not href or href in seen_urls:
|
||||
continue
|
||||
|
||||
href = link_el.get('href')
|
||||
if not href or '/p-' not in href:
|
||||
|
||||
# Filter out non-product links if any (e.g. facets)
|
||||
if '/p-' not in href:
|
||||
continue
|
||||
|
||||
seen_urls.add(href)
|
||||
url = self.make_absolute_url(href)
|
||||
|
||||
title_el = card.select_one("h3, div[class*='title'], span[class*='title']")
|
||||
title = title_el.get_text(strip=True) if title_el else link_el.get_text(strip=True)
|
||||
# Find the container: usually the link itself or a close parent
|
||||
# We look for a parent that contains price or image info
|
||||
container = link
|
||||
for _ in range(5): # Go up 5 levels max
|
||||
parent = container.parent
|
||||
if not parent:
|
||||
break
|
||||
container = parent
|
||||
# Stop if we hit a large container or list item
|
||||
if container.name == 'article' or (container.get('class') and any('list__item' in c for c in container.get('class'))):
|
||||
break
|
||||
# Stop if we find a price element inside this container that isn't the link itself
|
||||
if container.select_one("span[class*='price'], div[class*='price']"):
|
||||
break
|
||||
|
||||
# Title
|
||||
title = link.get('title')
|
||||
if not title:
|
||||
title_el = container.select_one("h3, div[class*='title'], span[class*='title']")
|
||||
if title_el:
|
||||
title = title_el.get_text(strip=True)
|
||||
if not title:
|
||||
title = link.get_text(strip=True)
|
||||
|
||||
if not title:
|
||||
continue
|
||||
|
||||
# Image
|
||||
img_url = None
|
||||
img_el = card.select_one("img")
|
||||
img_el = container.select_one("img")
|
||||
if img_el:
|
||||
img_url = self._get_image_src(img_el)
|
||||
if img_url:
|
||||
img_url = self.make_absolute_url(img_url)
|
||||
|
||||
# Price
|
||||
price = None
|
||||
price_el = card.select_one("div[class*='price'], span[class*='price'], .product-price")
|
||||
price_el = container.select_one("div[class*='price'], span[class*='price'], .product-price")
|
||||
if price_el:
|
||||
price = self.parse_price_text(price_el.get_text())
|
||||
|
||||
# Fallback price search in text
|
||||
# Fallback price search in text of container
|
||||
if not price:
|
||||
text = card.get_text(" ", strip=True)
|
||||
text = container.get_text(" ", strip=True)
|
||||
price = self.parse_price_text(text)
|
||||
|
||||
results.append(ProductResult(
|
||||
|
||||
Reference in new issue
Block a user