Search code examples
python-3.xgithubjupyter-notebookurllib

HTTPError: HTTP Error 404: Not Found in python 3


import urllib.request

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

I am trying to create this function but it throws me the below error-- HTTPError: HTTP Error 404: Not Found

Please help me with this.


Solution

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

    source: https://docs.python.org/3/howto/urllib2.html