【问题标题】:HTTPError: HTTP Error 404: Not Found in python 3HTTPError:HTTP 错误 404:在 python 3 中未找到
【发布时间】:2020-03-31 17:38:35
【问题描述】:
import urllib.request

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

我正在尝试创建这个函数,但它抛出了下面的error-- HTTPError: HTTP Error 404: Not Found

请帮帮我。

【问题讨论】:

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


    【解决方案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

    【讨论】:

      【解决方案2】:
      import urllib.request
      requ = urllib.request.Request(url='')
      with urllib.request.urlopen(requ) as f:
      data = f.read()
      

      试试这个,否则你可能需要一个 .decode 语句和 .read

      【讨论】:

        猜你喜欢
        • 2021-09-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-19
        • 2020-11-21
        • 2017-10-16
        • 1970-01-01
        • 2018-08-08
        相关资源
        最近更新 更多