HTTPError:HTTP错误404:在python 3中找不到

时间:2020-03-31 17:38:35

标签: python-3.x github jupyter-notebook urllib

import urllib.request

def get_site_html(url):
    source = urllib.request.urlopen(url).read()
    return source

我正在尝试创建此函数,但它向我抛出了以下error-- HTTPError: HTTP Error 404: Not Found

请帮助我。

2 个答案:

答案 0 :(得分:1)

import urllib.request

req = urllib.request.Request('your link here')
with urllib.request.urlopen(req) as response:
   the_page = response.read()

来源:https://docs.python.org/3/howto/urllib2.html

答案 1 :(得分:1)

import urllib.request
requ = urllib.request.Request(url='')
with urllib.request.urlopen(requ) as f:
data = f.read()

尝试此操作,否则您可能需要.decode语句以及.read