from urllib import request
import ssl

# ssl._create_default_https_context = ssl._create_unverified_context
def getHtml():
    # url = "https://m.80s.tw"
    url = "https://www.80s.tw"
    data = request.urlopen(url).read().decode("utf-8")
    return data

print(getHtml())

获取HTTPS的网页源码,是返回错误,

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

然后加上下面代码就可以了????

import ssl

ssl._create_default_https_context=ssl._create_unverified_context

 

相关文章:

  • 2021-12-01
  • 2021-12-22
  • 2021-05-21
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
相关资源
相似解决方案