mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-12 01:39:25 +02:00
feat: Implement direct e-commerce search service using Playwright/Browserless to scrape product information from various configured retail websites.
This commit is contained in:
1 parent
97039484fa
commit
ee8a14668c
1 file changed
+27
-17
@@ -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",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Bloquer les ressources inutiles
|
try:
|
||||||
await context.route("**/*.{png,jpg,jpeg,gif,webp,svg,ico}", lambda route: route.abort())
|
# Créer un nouveau contexte isolé pour ce site
|
||||||
await context.route("**/analytics*", lambda route: route.abort())
|
context = await browser.new_context(
|
||||||
await context.route("**/tracking*", lambda route: route.abort())
|
viewport={"width": 1920, "height": 1080},
|
||||||
|
user_agent=USER_AGENT,
|
||||||
|
locale="fr-FR",
|
||||||
|
timezone_id="Europe/Paris",
|
||||||
|
extra_http_headers={
|
||||||
|
"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",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
page = await context.new_page()
|
# 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))
|
||||||
|
|||||||
Reference in new issue
Block a user