Search code examples
pythonrequest

How to send requests to a downloaded html file


I have a .html file downloaded and want to send a request to this file to grab it's content.

However, if I do the following:

import requests
html_file  = "/user/some_html.html"
r = requests.get(html_file)

Gives the following error:

Invalid URL 'some_html.html': No schema supplied.

If I add a schema I get the following error:

HTTPConnectionPool(host='some_html.html', port=80): Max retries exceeded with url:

I want to know how to specifically send a request to a html file when it's downloaded.


Solution

  • You are accessing html file from local directory. get() method uses HTTPConnection and port 80 to access data from website not a local directory. To access file from local directory using get() method use Xampp or Wampp. for accessing file from local directory you can use open() while requests.get() is for accessing file from Port 80 using http Connection in simple word from internet not local directory

    import requests
    html_file  = "/user/some_html.html"
    t=open(html_file, "r")
    for v in t.readlines():
      print(v)
    

    Output: enter image description here