In this tutorial, we will discuss how we can download the Instagram images using Python script.

For this, we will require selenium, requests, and BeautifulSoup Python’s libraries to be installed in our machine.

Enter the following commands in your terminal one by one to install the above-required libraries.

Windows:

Mac:

We will also need a chrome driver to work with selenium and chrome browser. So I recommend you to download the version specific to your computer specs from here (Don’t worry driver file size is small :P).

Now as we have all the resources let’s write the python code to download Instagram images from python.

Result:

Running python script which downloads instagram images

successfully downloded image using python

In the above program using time.time() we are generating unique numbers for our file name so that each time we run the script the downloaded image file will have unique file names. Also, we are saving the file in the same directory, if you want to save the file into some different directory then provide the full path of your image file in open().

If you don’t know where your file is being downloaded or the path of your Python script then uses the following code in your program to print the path of your current script.

We have to use selenium because Instagram’s images are rendered using javascript which hides the image URL from the browser’s source, but selenium captures the source file after all the rendering have been finished therefore we get the complete HTML source file of the page so forth the URL of the Instagram’s post’s image.

If you have any doubts or suggestion then please comment below.

Leave a Reply