urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)>
複製代碼
經過修改模塊設置爲不用驗證證書便可html
from urllib.request import urlopen
from bs4 import BeautifulSoup
import logging
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
try:
url = "/wiki/Morgan_Freeman"
res_html = urlopen("https://en.wikipedia.org"+url).read() # return HTML of the website
soup = BeautifulSoup(res_html, 'html.parser') # beautiful soup object to be used for parsing html content
print(soup)
except:
logging.warning("Bad website url: %s", url)
複製代碼