取消chrome受自动控制提示
代码示例:
def __get_chrome_driver(self):
"""获取谷歌的驱动并执行"""
# 取消chrome受自动控制提示
chrome_options = Options()
chrome_options.add_argument('--disable-gpu') # 谷歌文档提到需要加上这个属性来规避bug
chrome_options.add_argument('lang=zh_CN.UTF-8') # 设置默认编码为utf-8
chrome_options.add_experimental_option('useAutomationExtension', False) # 取消chrome受自动控制提示
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) # 取消chrome受自动控制提示
# 指定webdriver文件下的谷歌驱动
chrome_driver_path = os.path.join(self.driver_path,'chromedriver.exe')
# 传入webdriver驱动的新方法 Service()函数;以前的报警告,即将弃用
chrome_driver_path_obj = Service(chrome_driver_path)
driver = webdriver.Chrome(service=chrome_driver_path_obj,options=chrome_options)
logger.info('初始化google浏览器并启动')
return driver
代码编写位置

原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/245453.html