python的selenium的帶https安全隱私問題解決方案
阿新 • • 發佈:2018-12-04
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()