mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-11 17:29:14 +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')",
|
||||
"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:
|
||||
pass
|
||||
|
||||
async def handle_cookie_banners(self, page: Page):
|
||||
"""Attempt to close cookie banners"""
|
||||
async def handle_popups(self, page: Page):
|
||||
"""Attempt to close cookie banners and popups"""
|
||||
try:
|
||||
for selector in COOKIE_ACCEPT_SELECTORS:
|
||||
if await page.locator(selector).first.is_visible(timeout=200):
|
||||
await page.locator(selector).first.click()
|
||||
logger.info(f"Closed cookie banner with {selector}")
|
||||
await asyncio.sleep(0.5)
|
||||
return
|
||||
# Check for multiple popups (cookies + promo)
|
||||
# We iterate through all selectors and click any that are visible
|
||||
# We do this in a loop to handle sequential popups
|
||||
for _ in range(3): # Try up to 3 times for sequential popups
|
||||
clicked_something = False
|
||||
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:
|
||||
pass
|
||||
|
||||
@@ -152,7 +165,7 @@ class BrowserlessService:
|
||||
# Retry logic could be handled here or by caller,
|
||||
# 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)
|
||||
|
||||
if wait_selector:
|
||||
|
||||
Reference in new issue
Block a user