爬虫常用技巧(4)-- 请求SSL证书验证

简单来说,就是忽略未经过认证的报错

代码

import requests

url = 'https://www.12306.cn/'

#  报错: requests.exceptions.SSLError
# res = requests.get(url)

res = requests.get(url, verify= False)

print(res.status_code)

运行结果

python@ubuntu:~/Desktop/pach$ python3 12306.py 
/usr/lib/python3/dist-packages/urllib3/connectionpool.py:794: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
  InsecureRequestWarning)
200

示例网站

这里写图片描述

联系方式

qq:2564493603
欢迎交流

猜你喜欢

转载自blog.csdn.net/Enjolras_fuu/article/details/81265870
今日推荐