In this section, we will learn how to use urllib2 and how we can build HTTP clients with that module.
Building an HTTP Client with urllib2
Introduction to urllib2
urllib2 can read data from a URL using various protocols, such as HTTP, HTTPS, FTP, or Gopher. This module provides urlopen function used to create an object similar to a file with which can to read from the URL. This object has methods such as read(), readline(), readlines(), and close(), which work exactly the same as in the file objects, although in reality we are working with a wrapper that abstracts us from using a socket at low level.
The read method, as you will remember, is used to read the complete "file" or the number of bytes specified as a...