Fix cookie banner GDPR care blocheaza click-ul pe LOGIN in deploy
Banner-ul GDPR aparea cu intarziere dupa page load si bloca click-ul. Adaugat wait explicit, mai multe strategii de text, force click si fallback JavaScript pentru eliminarea banner-ului din DOM. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -90,26 +90,44 @@ class BTGoScraper:
|
|||||||
)
|
)
|
||||||
logging.info(f"Progress update: {message}")
|
logging.info(f"Progress update: {message}")
|
||||||
|
|
||||||
def _dismiss_gdpr_cookies(self, page):
|
def _dismiss_gdpr_cookies(self, page, wait_for_banner=True):
|
||||||
"""
|
"""
|
||||||
Inchide GDPR cookie banner daca este vizibil
|
Inchide GDPR cookie banner daca este vizibil
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
page: Pagina Playwright pe care sa verifice
|
page: Pagina Playwright pe care sa verifice
|
||||||
|
wait_for_banner: Daca True, asteapta aparitia banner-ului inainte de a incerca
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
# Asteapta ca banner-ul GDPR sa apara (poate intarzia dupa page load)
|
||||||
|
if wait_for_banner:
|
||||||
|
try:
|
||||||
|
page.wait_for_selector(".gdprcookie-wrapper", timeout=5000, state="visible")
|
||||||
|
logging.info(" [INFO] Banner GDPR detectat, incerc sa-l inchid...")
|
||||||
|
except:
|
||||||
|
# Banner-ul nu a aparut in 5 secunde, continuam
|
||||||
|
pass
|
||||||
|
|
||||||
# Strategii pentru cookie consent (in ordinea probabilitatii)
|
# Strategii pentru cookie consent (in ordinea probabilitatii)
|
||||||
cookie_strategies = [
|
cookie_strategies = [
|
||||||
# 1. Noul buton BT (2024+)
|
# 1. Noul buton BT (2024+)
|
||||||
("role", "button", "Accept toate"),
|
("role", "button", "Accept toate"),
|
||||||
("role", "button", "Accepta toate"),
|
("role", "button", "Accepta toate"),
|
||||||
|
("role", "button", "Acceptă toate"),
|
||||||
|
|
||||||
# 2. Vechiul GDPR wrapper
|
# 2. Vechiul GDPR wrapper - text specific
|
||||||
("css", ".gdprcookie-wrapper button:has-text('Accept')"),
|
("css", ".gdprcookie-wrapper button:has-text('Accept')"),
|
||||||
("css", ".gdprcookie-wrapper button:has-text('Sunt de acord')"),
|
("css", ".gdprcookie-wrapper button:has-text('Sunt de acord')"),
|
||||||
("css", ".gdprcookie-wrapper button"),
|
("css", ".gdprcookie-wrapper button:has-text('Accepta')"),
|
||||||
|
("css", ".gdprcookie-wrapper button:has-text('Acceptă')"),
|
||||||
|
("css", ".gdprcookie-wrapper button:has-text('OK')"),
|
||||||
|
|
||||||
# 3. Fallback generic
|
# 3. GDPR wrapper - orice buton (fallback agresiv)
|
||||||
|
("css", ".gdprcookie-wrapper button"),
|
||||||
|
("css", ".gdprcookie-wrapper .btn"),
|
||||||
|
("css", ".gdprcookie-wrapper [role='button']"),
|
||||||
|
|
||||||
|
# 4. Fallback generic
|
||||||
("role", "button", "Accept"),
|
("role", "button", "Accept"),
|
||||||
("role", "button", "Accepta"),
|
("role", "button", "Accepta"),
|
||||||
("role", "button", "OK"),
|
("role", "button", "OK"),
|
||||||
@@ -122,10 +140,23 @@ class BTGoScraper:
|
|||||||
else:
|
else:
|
||||||
btn = page.locator(strategy[2]).first
|
btn = page.locator(strategy[2]).first
|
||||||
|
|
||||||
if btn.is_visible(timeout=2000):
|
if btn.is_visible(timeout=3000):
|
||||||
btn.click()
|
btn.click(force=True)
|
||||||
logging.info(f" [OK] Cookies acceptate ({strategy})")
|
logging.info(f" [OK] Cookies acceptate ({strategy})")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
# Verifica ca banner-ul a disparut
|
||||||
|
try:
|
||||||
|
page.wait_for_selector(".gdprcookie-wrapper", timeout=2000, state="hidden")
|
||||||
|
logging.info(" [OK] Banner GDPR inchis cu succes")
|
||||||
|
except:
|
||||||
|
# Incearca inca o data cu force click
|
||||||
|
logging.info(" [WARN] Banner inca vizibil, reincercare...")
|
||||||
|
try:
|
||||||
|
btn.click(force=True)
|
||||||
|
time.sleep(1)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
@@ -423,6 +454,17 @@ class BTGoScraper:
|
|||||||
logging.info("Verificare GDPR cookie banner...")
|
logging.info("Verificare GDPR cookie banner...")
|
||||||
self._dismiss_gdpr_cookies(self.page)
|
self._dismiss_gdpr_cookies(self.page)
|
||||||
|
|
||||||
|
# Verificare finala ca banner-ul nu mai blocheaza
|
||||||
|
try:
|
||||||
|
gdpr_wrapper = self.page.locator(".gdprcookie-wrapper")
|
||||||
|
if gdpr_wrapper.is_visible(timeout=1000):
|
||||||
|
logging.warning(" [WARN] Banner GDPR inca vizibil, fortez inchiderea...")
|
||||||
|
# Incearca sa inchida prin JavaScript
|
||||||
|
self.page.evaluate("document.querySelector('.gdprcookie-wrapper')?.remove()")
|
||||||
|
time.sleep(0.5)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# Click pe butonul LOGIN - deschide popup
|
# Click pe butonul LOGIN - deschide popup
|
||||||
logging.info("Click pe butonul LOGIN...")
|
logging.info("Click pe butonul LOGIN...")
|
||||||
with self.page.expect_popup() as popup_info:
|
with self.page.expect_popup() as popup_info:
|
||||||
|
|||||||
Reference in New Issue
Block a user