mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-22 14:48:13 +02:00
feat: Add centralized search configuration for sites, proxies, and user agents, and create browserless service module.
This commit is contained in:
1 parent
f665a000af
commit
22f8aedaa4
2 files changed
+35
-9
No files matched your search
@@ -203,4 +203,17 @@ COOKIE_ACCEPT_SELECTORS = [
|
|||||||
"button:has-text('Accepter tout')",
|
"button:has-text('Accepter tout')",
|
||||||
"button:has-text('Accepter')",
|
"button:has-text('Accepter')",
|
||||||
"button:has-text('J\\'accepte')",
|
"button:has-text('J\\'accepte')",
|
||||||
|
# Promotional Popups / Modals
|
||||||
|
".modal-close",
|
||||||
|
".close-modal",
|
||||||
|
".popup-close",
|
||||||
|
"button[aria-label='Close']",
|
||||||
|
"button[aria-label='Fermer']",
|
||||||
|
".js-modal-close",
|
||||||
|
"div[class*='popup'] button[class*='close']",
|
||||||
|
"div[class*='modal'] button[class*='close']",
|
||||||
|
# Specific Gifi/Discount popups
|
||||||
|
".popin-close",
|
||||||
|
"#popin-close",
|
||||||
|
"a.close-popin",
|
||||||
]
|
]
|
||||||
@@ -120,15 +120,28 @@ class BrowserlessService:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def handle_cookie_banners(self, page: Page):
|
async def handle_popups(self, page: Page):
|
||||||
"""Attempt to close cookie banners"""
|
"""Attempt to close cookie banners and popups"""
|
||||||
try:
|
try:
|
||||||
for selector in COOKIE_ACCEPT_SELECTORS:
|
# Check for multiple popups (cookies + promo)
|
||||||
if await page.locator(selector).first.is_visible(timeout=200):
|
# We iterate through all selectors and click any that are visible
|
||||||
await page.locator(selector).first.click()
|
# We do this in a loop to handle sequential popups
|
||||||
logger.info(f"Closed cookie banner with {selector}")
|
for _ in range(3): # Try up to 3 times for sequential popups
|
||||||
await asyncio.sleep(0.5)
|
clicked_something = False
|
||||||
return
|
for selector in COOKIE_ACCEPT_SELECTORS:
|
||||||
|
try:
|
||||||
|
# Use a short timeout for check
|
||||||
|
element = page.locator(selector).first
|
||||||
|
if await element.is_visible(timeout=100):
|
||||||
|
await element.click()
|
||||||
|
logger.info(f"Closed popup/banner with {selector}")
|
||||||
|
await asyncio.sleep(0.5) # Wait for animation
|
||||||
|
clicked_something = True
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not clicked_something:
|
||||||
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -152,7 +165,7 @@ class BrowserlessService:
|
|||||||
# Retry logic could be handled here or by caller,
|
# Retry logic could be handled here or by caller,
|
||||||
# for now we return what we have, caller decides
|
# for now we return what we have, caller decides
|
||||||
|
|
||||||
await self.handle_cookie_banners(page)
|
await self.handle_popups(page)
|
||||||
await self.simulate_human_behavior(page)
|
await self.simulate_human_behavior(page)
|
||||||
|
|
||||||
if wait_selector:
|
if wait_selector:
|
||||||
|
|||||||
Reference in new issue
Block a user