16/05/2022
🔑 PYTHON CHALLENGE #10 (File Downloader)
Using the requests module for instance, you can send a GET request to a web server to provide a web content or resource. Besides requesting for .html web pages, it can request for .jpg images, .mp4 videos, .exe executables, .js scripts or any other file type available out there! Provided you have the URL to that file.
Create a program that is able to get and save (download) any online resource from the Internet, using the URL provided by a user.
Such URL should point directly to a file on the web server, or your program would need to allow redirects to the destination file. Most of such URLs are gotten either by viewing the source code of the containing web page, or at the point of download on a web browser, and end with the filename (with extension). Use the URL below, if you cannot easily get one.
https://www.pngitem.com/pimgs/b/16-163788_watercolor-bouquet-png.png
(This is the URL to a PNG image of flowers hosted at pngitem.com's server. This URL should display the image when opened in a browser.)
Of course, your program should be able to save the file with either the filename of the online media (if available via the 'Content-Disposition' header) or the filename as suggested by the URL provided. The file should also be saved with the right file extension, such that your device would open it as expected. If for example, an MP4 video file is downloaded, it should be saved with a .mp4 file format, and play perfectly in a video player.
Additionally, your program should be sensitive to the 'Content-Type' header and/or the Status Code of the server response, to be sure the server has not responded with a web page (error page) instead, while a different file is intended to be downloaded. When, for instance, a wrong or inaccessible URL is entered, or an error occurs, the server may respond with an HTML error page instead. 404 Not Found error, may be.
HINT:
Remember, while certain files may come in plain texts, most files come as binary files.
Upon verifying that all files downloaded via your program behave as expected, push your code to Github, and post the repository link here.
Property of BeyondPapers Technologies by Akinpelumi Michael.
© 2022 Michael Akinpelumi, BeyondPapers
License: http://creativecommons.org/licenses/by/4.0/