如何判断webdriver和普通Chrome
启动Chrome窗口
from selenium import webdriver
driver = webdriver.Chrome(executable_path='/path/chromewebdriver')
在Chrome的开发者工具中打开Console选项卡
window.navigator.webdriver
如果是Chromedriver,返回true
,如果是普通的Chrome窗口,返回undefined
解决方案
启动Chromedriver之前,为Chrome开启实验性功能参数excludeSwitches
,它的值为['enable-automation']
,完整代码:
from selenium.webdriver import Chrome
from selenium.webdriver import ChromeOptions
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
driver = Chrome(options=option)