option = webdriver.ChromeOptions()标签:webdriver,浏览器,option,get,自动测试,selenium,cdp,path,browser From: https://blog.51cto.com/asura1992/6142853
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_experimental_option('useAutomationExtension', False)
driver_path = "C:/chromedriver.exe"
browser = webdriver.Chrome(driver_path,options=option)
browser.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument',
{'source': 'Object.defineProperty(navigator, "webdriver", {get: () => undefined})'})
browser.maximize_window() # 窗口最大化
# 这行代码的作用是将webdriver这个属性置为undefined
browser.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument',
{'source': 'Object.defineProperty(navigator, "webdriver", {get: () => undefined})'
})
browser.get("https://www.baidu.com")