ssl._create_default_https_context = ssl._create_unverified_context
发送请求时,指定urlopen参数
context = ssl._create_unverified_context()
html = urlopen("http://www.pythonscraping.com/exercises/exercise1.html",context=context)
在观看ssl库之后,我发现有一种更简单的方法
新建默认SSLContext对象,默认是不用进行ssl认证的
context=ssl.SSLContext()
html = urlopen("http://www.pythonscraping.com/exercises/exercise1.html",context=context)
import ssl
from urllib.request import urlopen
from bs4 import BeautifulSoup
context=ssl.SSLContext()
html = urlopen("http://www.pythonscraping.com/exercises/exercise1.html",context=context)
bsObj = BeautifulSoup(html, "html.parser")
print(bsObj.h1)