• <legend id='0gHBv'><style id='0gHBv'><dir id='0gHBv'><q id='0gHBv'></q></dir></style></legend>
  • <tfoot id='0gHBv'></tfoot>
      <bdo id='0gHBv'></bdo><ul id='0gHBv'></ul>

    <i id='0gHBv'><tr id='0gHBv'><dt id='0gHBv'><q id='0gHBv'><span id='0gHBv'><b id='0gHBv'><form id='0gHBv'><ins id='0gHBv'></ins><ul id='0gHBv'></ul><sub id='0gHBv'></sub></form><legend id='0gHBv'></legend><bdo id='0gHBv'><pre id='0gHBv'><center id='0gHBv'></center></pre></bdo></b><th id='0gHBv'></th></span></q></dt></tr></i><div id='0gHBv'><tfoot id='0gHBv'></tfoot><dl id='0gHBv'><fieldset id='0gHBv'></fieldset></dl></div>

    1. <small id='0gHBv'></small><noframes id='0gHBv'>

        如何使用 Selenium 处理证书?

        How to deal with certificates using Selenium?(如何使用 Selenium 处理证书?)

            <small id='SwWF0'></small><noframes id='SwWF0'>

              <tbody id='SwWF0'></tbody>
            <legend id='SwWF0'><style id='SwWF0'><dir id='SwWF0'><q id='SwWF0'></q></dir></style></legend><tfoot id='SwWF0'></tfoot>

                <bdo id='SwWF0'></bdo><ul id='SwWF0'></ul>
                • <i id='SwWF0'><tr id='SwWF0'><dt id='SwWF0'><q id='SwWF0'><span id='SwWF0'><b id='SwWF0'><form id='SwWF0'><ins id='SwWF0'></ins><ul id='SwWF0'></ul><sub id='SwWF0'></sub></form><legend id='SwWF0'></legend><bdo id='SwWF0'><pre id='SwWF0'><center id='SwWF0'></center></pre></bdo></b><th id='SwWF0'></th></span></q></dt></tr></i><div id='SwWF0'><tfoot id='SwWF0'></tfoot><dl id='SwWF0'><fieldset id='SwWF0'></fieldset></dl></div>

                  本文介绍了如何使用 Selenium 处理证书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I am using Selenium to launch a browser. How can I deal with the webpages (URLs) that will ask the browser to accept a certificate or not?

                  In Firefox, I may have a website like that asks me to accept its certificate like this:

                  On the Internet Explorer browser, I may get something like this:

                  On Google Chrome:

                  I repeat my question: How can I automate the acceptance of a website's certificate when I launch a browser (Internet Explorer, Firefox and Google Chrome) with Selenium (Python programming language)?

                  解决方案

                  For the Firefox, you need to set accept_untrusted_certs FirefoxProfile() option to True:

                  from selenium import webdriver
                  
                  profile = webdriver.FirefoxProfile()
                  profile.accept_untrusted_certs = True
                  
                  driver = webdriver.Firefox(firefox_profile=profile)
                  driver.get('https://cacert.org/')
                  
                  driver.close()
                  

                  For Chrome, you need to add --ignore-certificate-errors ChromeOptions() argument:

                  from selenium import webdriver
                  
                  options = webdriver.ChromeOptions()
                  options.add_argument('ignore-certificate-errors')
                  
                  driver = webdriver.Chrome(chrome_options=options)
                  driver.get('https://cacert.org/')
                  
                  driver.close()
                  

                  For the Internet Explorer, you need to set acceptSslCerts desired capability:

                  from selenium import webdriver
                  
                  capabilities = webdriver.DesiredCapabilities().INTERNETEXPLORER
                  capabilities['acceptSslCerts'] = True
                  
                  driver = webdriver.Ie(capabilities=capabilities)
                  driver.get('https://cacert.org/')
                  
                  driver.close()
                  


                  Actually, according to the Desired Capabilities documentation, setting acceptSslCerts capability to True should work for all browsers since it is a generic read/write capability:

                  acceptSslCerts

                  boolean

                  Whether the session should accept all SSL certs by default.


                  Working demo for Firefox:

                  >>> from selenium import webdriver
                  

                  Setting acceptSslCerts to False:

                  >>> capabilities = webdriver.DesiredCapabilities().FIREFOX
                  >>> capabilities['acceptSslCerts'] = False
                  >>> driver = webdriver.Firefox(capabilities=capabilities)
                  >>> driver.get('https://cacert.org/')
                  >>> print(driver.title)
                  Untrusted Connection
                  >>> driver.close()
                  

                  Setting acceptSslCerts to True:

                  >>> capabilities = webdriver.DesiredCapabilities().FIREFOX
                  >>> capabilities['acceptSslCerts'] = True
                  >>> driver = webdriver.Firefox(capabilities=capabilities)
                  >>> driver.get('https://cacert.org/')
                  >>> print(driver.title)
                  Welcome to CAcert.org
                  >>> driver.close()
                  

                  这篇关于如何使用 Selenium 处理证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)

                    <small id='B77vT'></small><noframes id='B77vT'>

                    <legend id='B77vT'><style id='B77vT'><dir id='B77vT'><q id='B77vT'></q></dir></style></legend>
                      <tbody id='B77vT'></tbody>
                    <tfoot id='B77vT'></tfoot>
                  1. <i id='B77vT'><tr id='B77vT'><dt id='B77vT'><q id='B77vT'><span id='B77vT'><b id='B77vT'><form id='B77vT'><ins id='B77vT'></ins><ul id='B77vT'></ul><sub id='B77vT'></sub></form><legend id='B77vT'></legend><bdo id='B77vT'><pre id='B77vT'><center id='B77vT'></center></pre></bdo></b><th id='B77vT'></th></span></q></dt></tr></i><div id='B77vT'><tfoot id='B77vT'></tfoot><dl id='B77vT'><fieldset id='B77vT'></fieldset></dl></div>

                        <bdo id='B77vT'></bdo><ul id='B77vT'></ul>