Here's an example of how to make an HTTP GET request in Python using the urllib
library:
main.py145 chars8 lines
In this example, we imported the urllib.request
module which provides a simple way to make HTTP requests in Python. We then specified the URL we want to request (https://www.example.com
) and used the urlopen()
method to send the GET request.
Once we have the response object, we can read the content of the response using the read()
method, which returns a byte string. We then decode this byte string into a regular string using the decode()
method.
Finally, we print the content of the response to the console.
gistlibby LogSnag