Python3-网页爬取-SSL验证

'''
SSL--校验网站证书----针对https,不针对http
一、什么是SSL证书
'''
from urllib import request
import ssl

#ssl免验证
#创建一个不需要验证的上下文
ssl._create_default_https_context=ssl._create_unverified_context
#而不是ssl._create_unverified_context()

# ssl._create_default_https_context = ssl._create_unverified_context
# base_url='http://www.12306.cn/mormhweb/'  #不报错
base_url = "https://www.csls.cdb.com.cn/" #urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED]

response = request.urlopen(base_url)
html = response.read()

# html = html.decode("utf-8")
print(html)
 
 

/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/apple/PycharmProjects/stage4/spider/20180305/08ssl.py
b'<html>\r\n<head>\r\n<title>\xb9\xfa\xbc\xd2\xbf\xaa\xb7\xa2\xd2\xf8\xd0\xd0 \xb8\xdf\xd0\xa3\xd6\xfa\xd1\xa7\xb4\xfb\xbf\xee\xcf\xb5\xcd\xb3</title>\r\n\t<script type="text/javascript">\r\n\t   function toOnline()\r\n\t   {\r\n\t      window.location="page.do?targetPage=/OnlineIndex.jsp";\r\n\t   }\r\n\r\n     toOnline(); \r\n\t</script> \r\n</head>\r\n<body> \r\n   <center>\r\n\r\n<table width=\'780\' height=200 style=\'background-color:#dff3df\'>\r\n<tr><td><br>&nbsp;\xbb\xb6\xd3\xad\xb7\xc3\xce\xca <b>\xb9\xfa\xbc\xd2\xbf\xaa\xb7\xa2\xd2\xf8\xd0\xd0 \xd6\xfa\xd1\xa7\xb4\xfb\xbf\xee\xcf\xb5\xcd\xb3</b> \xd5\xfd\xd4\xda\xbc\xd3\xd4\xd8\xcd\xf8\xd2\xb3\xa3\xac\xc7\xeb\xb5\xc8\xb4\xfd...</td></tr>\r\n<tr><td><br></td></tr>\r\n<tr><td height=100%></td></tr>\r\n</table>\r\n\r\n   </center>\r\n</body>\r\n</html>\r\n'


Process finished with exit code 0

猜你喜欢

转载自blog.csdn.net/zbrj12345/article/details/79926616
今日推荐