python urllib https抓取网页的问题

这是👉python urllib https抓取网页的问题👈的摘要

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
updatedupdated2023-01-292023-01-29
点击刷新