zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    shell-脚本_系统监测
    shell-脚本_防火墙规则的简单应用
    shell-命令_find
    shell-命令_cut
    shell-条件测试语句_test
    Error:java: 不再支持源选项 5。请使用 6 或更高版本。
    android项目删除recycleview相对应的数据库数据后闪退
    大作业--社团管理系统总结
    北京地铁出行路线代码分析
    北京地铁出行路线规划设计
  • 原文地址:https://www.cnblogs.com/lizm166/p/8193146.html
Copyright © 2011-2022 走看看