From 2e2b29537d1908ae2bab0677146873d2a4e91457 Mon Sep 17 00:00:00 2001 From: deedy5 <65482418+deedy5@users.noreply.github.com> Date: Sat, 17 Feb 2024 12:53:12 +0300 Subject: [PATCH] playwright chromium args: add --disable-blink-features=AutomationControlled --- fake_traffic/fake_traffic.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/fake_traffic/fake_traffic.py b/fake_traffic/fake_traffic.py index 87d016f..7bfe4f0 100644 --- a/fake_traffic/fake_traffic.py +++ b/fake_traffic/fake_traffic.py @@ -89,11 +89,11 @@ def __init__( max_wait=10, headless=True, ): - """ Imitating an Internet user by mimicking popular web traffic (internet traffic generator). + """Imitating an Internet user by mimicking popular web traffic (internet traffic generator). country = country code ISO 3166-1 Alpha-2 code (https://www.iso.org/obp/ui/), language = country-language code ISO-639 and ISO-3166 (https://www.fincher.org/Utilities/CountryLanguageList.shtml), - category = сategory of interest of a user (defaults to 'h'): - 'all' (all), 'b' (business), 'e' (entertainment), + category = category of interest of a user (defaults to 'h'): + 'all' (all), 'b' (business), 'e' (entertainment), 'm' (health), 's' (sports), 't' (sci/tech), 'h' (top stories); min_wait = minimal delay between requests (defaults to 1), max_wait = maximum delay between requests (defaults to 10), @@ -131,7 +131,11 @@ def initialize_browser(self): """Initialize browser""" try: p = sync_playwright().__enter__() - browser = p.chromium.launch(headless=self.headless, slow_mo=100) + browser = p.chromium.launch( + args=["--disable-blink-features=AutomationControlled"], + headless=self.headless, + slow_mo=100, + ) context = browser.new_context( locale=self.language, viewport={"width": 1920, "height": 1080}, @@ -162,9 +166,7 @@ def google_search(self, query): "//div[starts-with(@class, 'g ')]//span/a[@href]" ) result_urls = [link.get_attribute("href") for link in result_urls] - logging.info( - f"google_search() {query=} GOT {len(result_urls)} results" - ) + logging.info(f"google_search() {query=} GOT {len(result_urls)} results") return result_urls def google_trends(self):