Python 3 Script to Download Image or PDF File From URL Using Requests and Validators Library Full Project For Beginners

You are currently viewing Python 3 Script to Download Image or PDF File From URL Using Requests and Validators Library Full Project For Beginners

 

Welcome folks today in this tutorial we will be downloading image or pdf file from url using requests and validators libraries in python. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

In order to get started we need to install the following libraries using the pip command as shown below

 

pip install requests

 

pip install validators

 

After installing these libraries make an app.py file and copy paste the following code

 

app.py

 

 

 

 

Now to run this python script you need to provide an additonal command line argument in which you will be providing the url of the file to download in this script as shown below

 

Now to download a image from a url we will execute below command to run this script

 

python app.py https://freemediatools.com/img/profile.jpg

 

 

So as you can see the image is successfully downloaded with this script inside my root directory and in similar manner you can download any extension file such as pdf and any other media file like gif and video

Leave a Reply