天天看点

selenium 解决 SSL问题

在用selenium 进入12306时碰到的不受信任问题,网上查了是SSL问题

大部分解决方案是

from requests.packages.urllib3.exceptions import InsecureRequestWarning  

# 禁用安全请求警告  

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

但是我的这两句会报错,wtf,不知道是哪里的冲突(我是在win10上,python3.6)

后面在http://www.51testing.com/html/28/116228-827947.html处发现答案,找了好久,记录一下

from selenium import webdriver

browser=webdriver.Firefox()

profile = webdriver.FirefoxProfile()

profile.default_preferences["webdriver_assume_untrusted_issuer"]= 'false'

profile.update_preferences()

browser = webdriver.Firefox(profile)

browser.get('https://kyfw.12306.cn/otn/login/init')

----------------------------------------------------------------更新

import requests
import urllib3
from urllib3.exceptions import InsecureRequestWarning
urllib3.disable_warnings(InsecureRequestWarning)

sess = requests.session()
sess.verify = False
      

这样是最佳的