python – Scraping:SSL:http://en.wikipedia.org的CERTIFICATE_VERIFY_FAILED错误
作者:互联网
我正在练习’Web Scraping with Python‘的代码,我一直有这个证书问题:
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
pages = set()
def getLinks(pageUrl):
global pages
html = urlopen("http://en.wikipedia.org"+pageUrl)
bsObj = BeautifulSoup(html)
for link in bsObj.findAll("a", href=re.compile("^(/wiki/)")):
if 'href' in link.attrs:
if link.attrs['href'] not in pages:
#We have encountered a new page
newPage = link.attrs['href']
print(newPage)
pages.add(newPage)
getLinks(newPage)
getLinks("")
错误是:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1049)>
顺便说一句,我也在练习scrapy,但一直都在解决问题:找不到命令:scrapy(我在网上尝试过各种解决方案,但都没有用……真的很令人沮丧)
解决方法:
曾几何时我偶然发现了这个问题.如果您正在使用macOS,请转到Macintosh HD>应用程序> Python3.6文件夹(或者你正在使用的任何python版本)>双击“Install Certificates.command”文件. :d
标签:python,beautifulsoup,ssl-certificate,web-scraping,scrapy 来源: https://codeday.me/bug/20191003/1850947.html