diff --git a/app/services/parsers/generic_parser.py b/app/services/parsers/generic_parser.py index 65c1018..ca093d3 100644 --- a/app/services/parsers/generic_parser.py +++ b/app/services/parsers/generic_parser.py @@ -50,6 +50,8 @@ class GenericParser(BaseParser): Uses: - product_selector: CSS selector for product links - product_image_selector: CSS selector for images (optional) + + If configured selector fails, tries common fallback selectors. """ soup = BeautifulSoup(html, 'html.parser') products = [] @@ -62,8 +64,39 @@ class GenericParser(BaseParser): links = soup.select(product_selector) + # If configured selector fails, try common fallback selectors if not links: - self.logger.warning(f"No products found for {self.site_key} with selector: {product_selector}") + self.logger.warning(f"No products with configured selector: {product_selector}") + self.logger.info("Trying fallback selectors...") + + # Common e-commerce selectors (ordered by specificity) + fallback_selectors = [ + # Product-specific URLs + "a[href*='/produit']", + "a[href*='/product']", + "a[href*='/p/']", + "a[href*='/item']", + # Common class patterns + "article a[href]", + ".product a[href]", + ".product-card a[href]", + ".product-item a[href]", + "[class*='product'] a[href]", + # Generic structure + "article[class*='product'] a", + "div[class*='product'] a", + # Very generic (last resort) + "a[class*='product']", + ] + + for fallback in fallback_selectors: + links = soup.select(fallback) + if links and len(links) >= 3: # At least 3 links to be credible + self.logger.info(f"✓ Found {len(links)} links with fallback: {fallback}") + break + + if not links: + self.logger.warning(f"No products found for {self.site_key} even with fallbacks") return [] self.logger.info(f"Found {len(links)} product links for {self.site_name}")