Session Ready
Exercise

Printing HTTP request results in Python using urllib

You have just just packaged and sent a GET request to "http://www.datacamp.com/teach/documentation" and then caught the response. You saw that such a response is a http.client.HTTPResponse object. The question remains: what can you do with this response?

Well, as it came from an HTML page, you could read it to extract the HTML and, in fact, such a http.client.HTTPResponse object has an associated read() method. In this exercise, you'll build on your previous great work to extract the response and print the HTML.

Instructions
100 XP
  • Send the request and catch the response in the variable response with the function urlopen(), as in the previous exercise.
  • Extract the response using the read() method and store the result in the variable html.
  • Print the string html.
  • Hit submit to perform all of the above and to close the response: be tidy!