How it works

The URL is defined as a constant  const.ApodEclipseImage() in the const module:

def ApodEclipseImage():    return "https://apod.nasa.gov/apod/image/1709/BT5643s.jpg"

The constructor of the URLUtility class has the following implementation:

def __init__(self, url, readNow=True):    """ Construct the object, parse the URL, and download now if specified"""    self._url = url    self._response = None    self._parsed = urlparse(url)    if readNow:        self.read()

The constructor stores the URL, parses it, and downloads the file with the read() method.  The following is the code of the read() method:

def read(self):    self._response = urllib.request.urlopen(self._url)    self._data = self._response.read()

This function uses urlopen to get a response object, ...

Get Python Web Scraping Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.