如何修复Beautifulsoup SSL CERTIFICATE_VERIFY_FAILED错误

时间:2019-03-11 06:29:33

标签: python-3.x url beautifulsoup ssl-certificate urlopen

代码:

import requests

from bs4 import BeautifulSoup

from urllib.request import Request, urlopen

html = urlopen("https://www.familyeducation.com/baby-names/browse-origin/surname/german")

soup = BeautifulSoup(html)

metadata=soup.find_all('meta')

错误:

  

urlopen错误[SSL:CERTIFICATE_VERIFY_FAILED]

1 个答案:

答案 0 :(得分:0)

对于此错误,请查看以下答案: urllib and "SSL: CERTIFICATE_VERIFY_FAILED" Error

但是您不必总是为urlopen使用html request。您也可以通过requests lib发送请求。试试这个:

import requests

from bs4 import BeautifulSoup

html = requests.get("https://www.familyeducation.com/baby-names/browse-origin/surname/german")

soup = BeautifulSoup(html.text, "html.parser")

metadata = soup.find_all('meta')