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

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

    As mentioned in the above comment - https://stackoverflow.com/a/60403652/2923098 the following option totally worked for me (in Java)-

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--incognito", "--disable-blink-features=AutomationControlled");
    
    0 讨论(0)
  • 2020-11-22 01:26

    ChromeDriver:

    Finally discovered the simple solution for this with a simple flag! :)

    --disable-blink-features=AutomationControlled
    

    navigator.webdriver=true will no longer show up with that flag set.

    For a list of things you can disable, check them out here

    0 讨论(0)
  • 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)
    
    0 讨论(0)
  • 2020-11-22 01:32

    Before (in browser console window):

    > navigator.webdriver
    true
    

    Change (in selenium):

    // C#
    var options = new ChromeOptions();
    options.AddExcludedArguments(new List<string>() { "enable-automation" });
    
    // Python
    options.add_experimental_option("excludeSwitches", ['enable-automation'])
    

    After (in browser console window):

    > navigator.webdriver
    undefined
    

    This will not work for version ChromeDriver 79.0.3945.16 and above. See the release notes here

    0 讨论(0)
提交回复
热议问题