Downloading media content from the web
Downloading media content from the web is a simple process: use Requests or another library and download it just like you would HTML content.
Getting ready
There is a class named URLUtility
in the urls.py mdoule
in the util
folder of the solution. This class handles several of the scenarios in this chapter with downloading and parsing URLs. We will be using this class in this recipe and a few others. Make sure the modules
folder is in your Python path. Also, the example for this recipe is in the 04/01_download_image.py
file.
How to do it
Here is how we proceed with the recipe:
- The
URLUtility
class can download content from a URL. The code in the recipe's file is the following:
import const from util.urls import URLUtility util = URLUtility(const.ApodEclipseImage()) print(len(util.data))
- When running this you will see the following output:
Reading URL: https://apod.nasa.gov/apod/image/1709/BT5643s.jpg Read 171014 bytes 171014
The example reads 171014
bytes...