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

前端 未结 10 1056
既然无缘
既然无缘 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:17

    Nowadays you can accomplish this with cdp command:

    driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
      "source": """
        Object.defineProperty(navigator, 'webdriver', {
          get: () => undefined
        })
      """
    })
    
    driver.get(some_url)
    

    by the way, you want to return undefined, false is a dead giveaway.

提交回复
热议问题