报废:SSL:http://en.wikipedia.org的CERTIFICATE_VERIFY_FAILED错误 [英] Scraping: SSL: CERTIFICATE_VERIFY_FAILED error for http://en.wikipedia.org

查看:115
本文介绍了报废:SSL:http://en.wikipedia.org的CERTIFICATE_VERIFY_FAILED错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在练习使用Python进行网页搜刮"中的代码,但我仍然遇到此证书问题:

I'm practicing the code from 'Web Scraping with Python', and I keep having this certificate problem:

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(我在线尝试了各种解决方案,但都没有效果……真令人沮丧)

Btw,I was also practicing scrapy, but kept getting the problem: command not found: scrapy (I tried all sorts of solutions online but none works... really frustrating)

推荐答案

从前,我偶然发现了这个问题.如果您使用的是macOS,请转至Macintosh HD>应用程序> Python3.6文件夹(或您使用的任何版本的python)>双击"Install Certificates.command"文件. :D

Once upon a time I stumbled with this issue. If you're using macOS go to Macintosh HD > Applications > Python3.6 folder (or whatever version of python you're using) > double click on "Install Certificates.command" file. :D

这篇关于报废:SSL:http://en.wikipedia.org的CERTIFICATE_VERIFY_FAILED错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆