如何处理使用Selenium证书吗? [英] How to deal with certificates using Selenium?

查看:890
本文介绍了如何处理使用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?

在Firefox中,我可能有一个网站一样,要求我接受这样的证书:

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

在Internet Explorer浏览器,我可能会得到这样的:

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

在谷歌浏览器:

我重复我的问题:如何可以自动接受网站的证书时,我与硒(Python编程语言)启动一个浏览器(IE,火狐和谷歌Chrome)

推荐答案

有关Firefox的,你需要设置 accept_untrusted_certs FirefoxProfile()选项

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()

有关浏览器,你需要添加<一个href=\"http://peter.sh/experiments/chromium-command-line-switches/#ignore-certificate-errors\"><$c$c>--ignore-certificate-errors ChromeOptions()参数:

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()

对于Internet Explorer,您需要设置<一个href=\"https://$c$c.google.com/p/selenium/wiki/DesiredCapabilities#IE_specific\"><$c$c>acceptSslCerts所需能力:

from selenium import webdriver

capabilities = webdriver.DesiredCapabilities().INTERNETEXPLORER
capabilities['acceptSslCerts'] = True

driver = webdriver.Ie(capabilities=capabilities)
driver.get('https://cacert.org/')

driver.close()


事实上,根据 所需的功能文档,设置 acceptSslCerts 能力应当为所有的浏览器,因为它是一个通用的读/写功能:


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

acceptSslCerts

布尔

会议是否应该接受所有SSL证书
  在默认情况下。

Whether the session should accept all SSL certs by default.

有关Firefox的工作演示:


Working demo for Firefox:

>>> from selenium import webdriver

设置 acceptSslCerts

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

设置 acceptSslCerts

>>> 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证书吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆