feat: Implement direct e-commerce search service using Playwright/Browserless to scrape product information from various configured retail websites.

This commit is contained in:
Michael committed 2025-11-24 13:04:03 +01:00
1 parent 97039484fa
commit ee8a14668c
1 file changed
+29 -19
+29 -19
View File
@@ -555,26 +555,36 @@ async def _search_site_browserless( # noqa: PLR0912, PLR0915
context = None context = None
page = None page = None
max_retries = 3 if "amazon" in domain else 1
try: for attempt in range(max_retries):
# Créer un nouveau contexte isolé pour ce site if attempt > 0:
context = await browser.new_context( # Exponential backoff with jitter for Amazon retries
viewport={"width": 1920, "height": 1080}, base_delay = AMAZON_BASE_DELAY * (2 ** attempt)
user_agent=USER_AGENT, jitter = random.uniform(0.5, 1.5)
locale="fr-FR", delay = min(base_delay * jitter, AMAZON_MAX_DELAY)
timezone_id="Europe/Paris", logger.info(f"Amazon retry {attempt + 1}/{max_retries} for '{query}' after {delay:.1f}s delay")
extra_http_headers={ await asyncio.sleep(delay)
"Accept-Language": "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", try:
} # Créer un nouveau contexte isolé pour ce site
) context = await browser.new_context(
viewport={"width": 1920, "height": 1080},
# Bloquer les ressources inutiles user_agent=USER_AGENT,
await context.route("**/*.{png,jpg,jpeg,gif,webp,svg,ico}", lambda route: route.abort()) locale="fr-FR",
await context.route("**/analytics*", lambda route: route.abort()) timezone_id="Europe/Paris",
await context.route("**/tracking*", lambda route: route.abort()) extra_http_headers={
"Accept-Language": "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7",
page = await context.new_page() "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
}
)
# Bloquer les ressources inutiles
await context.route("**/*.{png,jpg,jpeg,gif,webp,svg,ico}", lambda route: route.abort())
await context.route("**/analytics*", lambda route: route.abort())
await context.route("**/tracking*", lambda route: route.abort())
page = await context.new_page()
# Naviguer vers la page de recherche # Naviguer vers la page de recherche
await page.goto(final_url, wait_until="domcontentloaded", timeout=int(timeout * 1000)) await page.goto(final_url, wait_until="domcontentloaded", timeout=int(timeout * 1000))