mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-19 13:18:12 +02:00
feat: Implement web scraping and search system with centralized configuration, browserless integration, and a verification script.
This commit is contained in:
1 parent
7f85a9764c
commit
f976ae1127
4 files changed
+87
-25
No files matched your search
+25
-15
@@ -51,6 +51,9 @@ USER_AGENT_POOL = [
|
||||
# Firefox Windows
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0",
|
||||
# Recent Chrome
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
|
||||
]
|
||||
|
||||
def get_random_user_agent() -> str:
|
||||
@@ -62,16 +65,16 @@ SITE_CONFIGS = {
|
||||
"gifi.fr": {
|
||||
"name": "Gifi",
|
||||
"search_url": "https://www.gifi.fr/resultat-recherche?q={query}",
|
||||
"product_selector": "a.link, .product-item a.link, .product-tile a.link",
|
||||
"wait_selector": ".product-item, .product-tile, .products-grid",
|
||||
"product_selector": "a.link",
|
||||
"wait_selector": ".product-tile",
|
||||
"category": "Discount",
|
||||
"requires_proxy": False,
|
||||
},
|
||||
"stokomani.fr": {
|
||||
"name": "Stokomani",
|
||||
"search_url": "https://www.stokomani.fr/search?options%5Bprefix%5D=last&q={query}",
|
||||
"product_selector": ".product-card__title a",
|
||||
"wait_selector": ".product-card__title a",
|
||||
"product_selector": "a.reversed-link.block",
|
||||
"wait_selector": "a.reversed-link.block",
|
||||
"category": "Discount",
|
||||
"requires_proxy": False,
|
||||
},
|
||||
@@ -83,12 +86,20 @@ SITE_CONFIGS = {
|
||||
},
|
||||
"lafoirfouille.fr": {
|
||||
"name": "La Foir'Fouille",
|
||||
"search_url": "https://www.lafoirfouille.fr/catalogsearch/result/?q={query}",
|
||||
"search_url": "https://www.lafoirfouille.fr/?q={query}",
|
||||
"product_selector": ".product-item a.product-item-link, .product-item-info a",
|
||||
"wait_selector": ".products-grid, .product-items",
|
||||
"category": "Discount",
|
||||
"requires_proxy": False,
|
||||
},
|
||||
"auchan.fr": {
|
||||
"name": "Auchan",
|
||||
"search_url": "https://www.auchan.fr/recherche?text={query}",
|
||||
"product_selector": "a[href*='/p-']",
|
||||
"wait_selector": "a[href*='/p-']",
|
||||
"category": "Grande Surface",
|
||||
"requires_proxy": False,
|
||||
},
|
||||
"centrakor.com": {
|
||||
"name": "Centrakor",
|
||||
"search_url": "https://www.centrakor.com/catalogsearch/result/?q={query}",
|
||||
@@ -96,7 +107,7 @@ SITE_CONFIGS = {
|
||||
"wait_selector": ".products-grid, .product-items",
|
||||
"category": "Déco & Maison",
|
||||
"requires_proxy": False,
|
||||
"pre_search_selector": "text=\"C'est parti !\"",
|
||||
"pre_search_selector": "button.storelocator-search__button--go",
|
||||
},
|
||||
"lincroyable.fr": {
|
||||
"name": "L'Incroyable",
|
||||
@@ -106,15 +117,6 @@ SITE_CONFIGS = {
|
||||
"category": "Déco & Maison",
|
||||
"requires_proxy": False,
|
||||
},
|
||||
"action.com": {
|
||||
"name": "Action",
|
||||
"search_url": "https://www.action.com/fr-fr/search/?q={query}",
|
||||
"product_selector": "a[href^='/fr-fr/p/']",
|
||||
"wait_selector": "a[href^='/fr-fr/p/']",
|
||||
"category": "Discount",
|
||||
"requires_proxy": False,
|
||||
},
|
||||
# === GRANDES SURFACES ===
|
||||
"e.leclerc": {
|
||||
"name": "E.Leclerc",
|
||||
"search_url": "https://www.e.leclerc/recherche?q={query}",
|
||||
@@ -123,6 +125,14 @@ SITE_CONFIGS = {
|
||||
"category": "Grande Surface",
|
||||
"requires_proxy": False,
|
||||
},
|
||||
"carrefour.fr": {
|
||||
"name": "Carrefour",
|
||||
"search_url": "https://www.carrefour.fr/s?q={query}",
|
||||
"product_selector": "a.product-card-click-wrapper",
|
||||
"wait_selector": "a.product-card-click-wrapper",
|
||||
"category": "Grande Surface",
|
||||
"requires_proxy": True,
|
||||
},
|
||||
# === E-COMMERCE GÉNÉRALISTE ===
|
||||
"amazon.fr": {
|
||||
"name": "Amazon France",
|
||||
|
||||
@@ -93,9 +93,6 @@ class BrowserlessService:
|
||||
|
||||
context = await self._browser.new_context(**options)
|
||||
|
||||
# Inject Stealth JS
|
||||
await context.add_init_script(STEALTH_JS)
|
||||
|
||||
# Block aggressive tracking but keep images for visual verification if needed
|
||||
# (Optimized for speed vs detection)
|
||||
await context.route("**/*", lambda route: route.continue_())
|
||||
|
||||
@@ -185,14 +185,27 @@ class NewSearchService:
|
||||
|
||||
# Extract title
|
||||
title = link.get_text(strip=True)
|
||||
if not title:
|
||||
# Try finding title in children or attributes
|
||||
img = link.find("img")
|
||||
if img and img.get("alt"):
|
||||
title = img.get("alt")
|
||||
elif link.get("title"):
|
||||
title = link.get("title")
|
||||
|
||||
# If no text, check title attribute or nested image alt
|
||||
if not title:
|
||||
if link.get("title"):
|
||||
title = link.get("title")
|
||||
else:
|
||||
img = link.find("img")
|
||||
if img and img.get("alt"):
|
||||
title = img.get("alt")
|
||||
|
||||
# Special case for Stokomani or similar where link might be wrapping text but get_text failed or we selected a container
|
||||
if not title and config.get("name") == "Stokomani":
|
||||
# If we selected the container .product-card__title, the link is inside
|
||||
child_link = link.find("a")
|
||||
if child_link:
|
||||
title = child_link.get_text(strip=True)
|
||||
if not href: # Update href if we selected a container
|
||||
href = child_link.get("href")
|
||||
if href:
|
||||
full_url = urljoin(base_url, href)
|
||||
|
||||
if not title or len(title) < 3:
|
||||
continue
|
||||
|
||||
|
||||
Reference in new issue
Block a user