Update changes
Dieser Commit ist enthalten in:
@ -1,11 +1,14 @@
|
||||
"""
|
||||
Cookie Consent Handler für Browser-Sessions
|
||||
|
||||
Behandelt Cookie-Consent-Seiten bei der Session-Wiederherstellung
|
||||
Behandelt Cookie-Consent-Seiten bei der Session-Wiederherstellung.
|
||||
Enthält Anti-Detection-Maßnahmen wie Lese-Pausen.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import Optional
|
||||
import time
|
||||
import random
|
||||
from typing import Optional, Any
|
||||
from playwright.sync_api import Page
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -15,20 +18,25 @@ class CookieConsentHandler:
|
||||
"""Behandelt Cookie-Consent-Dialoge verschiedener Plattformen"""
|
||||
|
||||
@staticmethod
|
||||
def handle_instagram_consent(page: Page) -> bool:
|
||||
def handle_instagram_consent(page: Page, human_behavior: Any = None) -> bool:
|
||||
"""
|
||||
Behandelt Instagram's Cookie-Consent-Seite
|
||||
|
||||
Behandelt Instagram's Cookie-Consent-Seite mit realistischer Lese-Zeit.
|
||||
|
||||
Diese Methode simuliert menschliches Verhalten durch eine Pause
|
||||
bevor der Cookie-Dialog geklickt wird. Echte Menschen lesen den
|
||||
Cookie-Text bevor sie auf einen Button klicken.
|
||||
|
||||
Args:
|
||||
page: Playwright Page-Objekt
|
||||
|
||||
human_behavior: Optional HumanBehavior-Instanz für realistische Delays
|
||||
|
||||
Returns:
|
||||
bool: True wenn Consent behandelt wurde, False sonst
|
||||
"""
|
||||
try:
|
||||
# Warte kurz auf Seitenladung
|
||||
page.wait_for_load_state('networkidle', timeout=5000)
|
||||
|
||||
|
||||
# Prüfe ob wir auf der Cookie-Consent-Seite sind
|
||||
consent_indicators = [
|
||||
# Deutsche Texte
|
||||
@ -57,7 +65,28 @@ class CookieConsentHandler:
|
||||
button = page.locator(button_selector).first
|
||||
if button.is_visible():
|
||||
logger.info(f"Found consent decline button: {button_selector}")
|
||||
|
||||
|
||||
# ANTI-DETECTION: Realistische Lese-Pause bevor Cookie-Dialog geklickt wird
|
||||
# Simuliert das Lesen der Cookie-Informationen (3-8 Sekunden)
|
||||
if human_behavior and hasattr(human_behavior, 'anti_detection_delay'):
|
||||
logger.debug("Cookie-Banner erkannt - simuliere Lesen...")
|
||||
human_behavior.anti_detection_delay("cookie_reading")
|
||||
else:
|
||||
# Fallback ohne HumanBehavior
|
||||
read_delay = random.uniform(3.0, 8.0)
|
||||
logger.debug(f"Cookie-Banner Lese-Pause: {read_delay:.1f}s")
|
||||
time.sleep(read_delay)
|
||||
|
||||
# Gelegentlich etwas scrollen um "mehr zu lesen" (30% Chance)
|
||||
if random.random() < 0.3:
|
||||
try:
|
||||
page.evaluate("window.scrollBy(0, 50)")
|
||||
time.sleep(random.uniform(0.8, 1.5))
|
||||
page.evaluate("window.scrollBy(0, -50)")
|
||||
time.sleep(random.uniform(0.3, 0.6))
|
||||
except:
|
||||
pass
|
||||
|
||||
# Verwende robuste Click-Methoden für Cookie-Consent
|
||||
success = False
|
||||
try:
|
||||
@ -233,19 +262,21 @@ class CookieConsentHandler:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def check_and_handle_consent(page: Page, platform: str = "instagram") -> bool:
|
||||
def check_and_handle_consent(page: Page, platform: str = "instagram",
|
||||
human_behavior: Any = None) -> bool:
|
||||
"""
|
||||
Prüft und behandelt Cookie-Consent für die angegebene Plattform
|
||||
|
||||
Prüft und behandelt Cookie-Consent für die angegebene Plattform.
|
||||
|
||||
Args:
|
||||
page: Playwright Page-Objekt
|
||||
platform: Plattform-Name (default: "instagram")
|
||||
|
||||
human_behavior: Optional HumanBehavior-Instanz für realistische Delays
|
||||
|
||||
Returns:
|
||||
bool: True wenn Consent behandelt wurde, False sonst
|
||||
"""
|
||||
if platform.lower() == "instagram":
|
||||
return CookieConsentHandler.handle_instagram_consent(page)
|
||||
return CookieConsentHandler.handle_instagram_consent(page, human_behavior)
|
||||
else:
|
||||
logger.warning(f"No consent handler implemented for platform: {platform}")
|
||||
return False
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren