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 imageitem = URLUtility(const.ApodEclipseImage())# create a file writer to write the dataFileBlobWriter(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.jpgRead 171014 bytesAttempting to write 171014 bytes to BT5643s.jpg:The write was successful

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.