This commit is contained in:
2026-08-31 20:47:06 +02:00
parent 078fe5323f
commit 94fb6a8568
2 changed files with 16 additions and 1 deletions
+14 -1
View File
@@ -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)