web自动化脚本操作https请求时,应该如何处理,针对不同浏览器,处理方式不同:
1.Chrome浏览器:需要添加ChromeOptions()的--ignore-certificate-errors选项为True
#_*_ coding:utf-8 _*_
from selenium import webdriver
if __name__ == '__main__':
options=webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
driver=webdriver.Chrome(chrome_options=options)
driver.get(u'https://cacert.org/')
driver.close()
2.FIRfOX浏览器:需要添加FirefoxProfile()的accept_untrusted_certs的选项为True
#_*_ coding:utf-8 _*_
from selenium import webdriver
if __name__ == '__main__':
profile=webdriver.FirefoxProfile()
profile.accept_untrusted_certs=True
driver=webdriver.Firefox(firefox_profile=profile)
driver.get(u'https://cacert.org/')
driver.close()
3、IE浏览器:需要添加Desired Capabilities的acceptSslCerts选项为True
#_*_ coding:utf-8 _*_
from selenium import webdriver
if __name__ == '__main__':
profile=webdriver.FirefoxProfile()
profile.accept_untrusted_certs=True
driver=webdriver.Firefox(firefox_profile=profile)
driver.get(u'https://cacert.org/')
driver.close()