Python3.x:chrome运行webdriver脚本提示--ignore-certificate-errors

Python3.x:chrome运行webdriver脚本提示--ignore-certificate-errors

1,分析原因:

 

 根本原因是Chromedriver和Chrome的版本不兼容;

 网上很多方案说加上如下代码可以解决,但是我试过了Chromedriver和Chrome的版本不兼容加上这段代码一样解决不了,兼容了不用这段代码也可以正常显示:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches",["ignore-certificate-errors"])
options.add_argument('test-type')
browser = webdriver.Chrome(chrome_options=options)

2,解决方案:

 chromedriver下载地址:http://chromedriver.storage.googleapis.com/index.html

 chromedriver与chrome的对应关系表:

解压压缩包,找到chromedriver.exe复制到chrome的安装目录(其实也可以随便放一个文件夹)。复制chromedriver.exe文件的路径并加入到电脑的环境变量中去。

例如:双击PATH,将你的文件位置(C:UsersmyAppDataLocalGoogleChromeApplication)添加到后面;

完成后在cmd下输入chromedriver验证是否安装成功:

 3,python3.x实例代码:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches",["ignore-certificate-errors"])
options.add_argument('test-type')
browser = webdriver.Chrome(chrome_options=options)

#driver = webdriver.Chrome()
browser.get("http://www.baidu.com")

print('success')

 或者

from selenium import webdriver

browser = webdriver.Chrome()
browser.get("http://www.baidu.com")

print('success')

 以上两种方式都可以实现;

4,结果:

 测试版本供参考:chromedriver v2.34与chrome v61

原文地址:https://www.cnblogs.com/lizm166/p/8193146.html