如何正确移除Selenium中的 window.navigator.webdriver

By | May 26, 2020

Chrome 79.0.3945.36+

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path='./chromedriver')
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () = undefined
})
"""

})
driver.get('http://google.com')

Chrome 旧版本

from selenium.webdriver import Chrome
from selenium.webdriver import ChromeOptions

option = ChromeOptions()
option.add_experimental_option('excludeSwitches',['enable-automation'])
driver =Chrome(options=option)

Leave a Reply

Your email address will not be published.