From 94fb6a856849cd1c2abb1a37048ad3d53b38cd3f Mon Sep 17 00:00:00 2001 From: Vysyr Date: Mon, 31 Aug 2026 20:47:06 +0200 Subject: [PATCH] sync --- README.md | 2 ++ scraper.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d04d293..0d81440 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ Google może czasem pokazać niezalogowanej przeglądarce „ograniczony widok Jeśli ograniczony widok pojawia się stale, można utworzyć osobny profil Chromium, zalogować go ręcznie i ustawić `CHROMIUM_PROFILE_PATH`. Profil przechowuje sesję przeglądarki; aplikacja nadal nie zapisuje opinii. +Jeśli Google ogranicza wyłącznie tryb bez okna, ustaw `CHROMIUM_HEADLESS=0` i uruchom proces na zwykłym albo wirtualnym ekranie (`xvfb-run`). + ## Testy ```bash diff --git a/scraper.py b/scraper.py index fbb8da8..2c9cd78 100644 --- a/scraper.py +++ b/scraper.py @@ -102,7 +102,17 @@ def get_rating_distribution(url: str) -> dict: """Pobiera pięć zbiorczych liczników. Treści opinii nie są odczytywane ani zapisywane.""" try: with sync_playwright() as playwright: - launch = {"headless": True, "args": ["--disable-dev-shm-usage", "--no-first-run", "--disable-gpu"]} + headless = os.environ.get("CHROMIUM_HEADLESS", "1").lower() not in {"0", "false", "no"} + launch = { + "headless": headless, + "ignore_default_args": ["--enable-automation"], + "args": [ + "--disable-dev-shm-usage", + "--no-first-run", + "--disable-gpu", + "--disable-blink-features=AutomationControlled", + ], + } if os.environ.get("CHROMIUM_PATH"): launch["executable_path"] = os.environ["CHROMIUM_PATH"] profile_path = os.environ.get("CHROMIUM_PROFILE_PATH") @@ -122,6 +132,9 @@ def get_rating_distribution(url: str) -> dict: context = browser.new_context(locale="pl-PL", viewport={"width": 1100, "height": 800}) try: page = context.pages[0] if context.pages else context.new_page() + context.add_init_script( + "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})" + ) page.goto(url, wait_until="domcontentloaded", timeout=30_000) _accept_cookies(page) _open_reviews(page)