In this tutorial, we will discuss how we can download the Instagram images using Python script.
Enter the following commands in your terminal one by one to install the above-required libraries.
pip install selenium
pip install requests
pip install bs4
sudo pip3 install selenium
sudo pip3 install requests
sudo pip3 install bs4
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.
#python script to download instagram image
from bs4 import BeautifulSoup
from selenium import webdriver
''' Ask user to input the instagram post url '''
link = input("Enter Instagram Image URL: ")
''' Create a wbdriver's chrome object by passing the path of 'chromedriver.exe' file.
Do not include .exe in the path, mine chromedrivers.exe is in the same folder where
this python script is '''
driver = webdriver.Chrome('chromedriver')
''' This statement will open the insatram post into your chrome browser'''
''' Fetching souce file of the html page using BeautifulSoup'''
soup = BeautifulSoup(driver.page_source, 'lxml')
''' Extracting the image url from the html page'''
img = soup.find('img', class_='FFVAD')
img_url = img['src']
'''Downloading the image from the url using requests'''
r = requests.get(img_url)
with open("instagram"+str(time.time())+".png",'wb') as f:
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
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.
If you have any doubts or suggestion then please comment below.