Selenium webdriver: Modifying navigator.webdriver flag to prevent selenium detection

前端 未结 10 851
既然无缘
既然无缘 2020-11-22 00:57

I\'m trying to automate a very basic task in a website using selenium and chrome but somehow the website detects when chrome is driven by selenium and blocks every request.

10条回答
  •  故里飘歌
    2020-11-22 01:28

    If you use a Remote Webdriver , the code below will set navigator.webdriver to undefined.

    work for ChromeDriver 81.0.4044.122

    Python example:

        options = webdriver.ChromeOptions()
        # options.add_argument("--headless")
        options.add_argument('--disable-gpu')
        options.add_argument('--no-sandbox')
        driver = webdriver.Remote(
           'localhost:9515', desired_capabilities=options.to_capabilities())
        script = '''
        Object.defineProperty(navigator, 'webdriver', {
            get: () => undefined
        })
        '''
        driver.execute_script(script)
    

提交回复
热议问题