Sometimes when scraping we just download and parse data, such as HTML, to extract some data, and then throw out what we read. Other times, we want to keep the downloaded content by storing it as a file.
Downloading and saving images to the local file system
How to do it
The code example for this recipe is in the 04/05_save_image_as_file.py file. The portion of the file of importance is:
# download the image
item = URLUtility(const.ApodEclipseImage())
# create a file writer to write the data
FileBlobWriter(expanduser("~")).write(item.filename, item.data)
Run the script with your Python interpreter and you will get the following output:
Reading URL: https://apod.nasa.gov/apod/image/1709/BT5643s.jpg
Read 171014 bytes
Attempting...