Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Download Instagram profile pic using Python

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Instagram is a photo and video-sharing social networking service owned by Facebook, Python provides powerful tools for web scraping of Instagram.

Modules required and Installation:


pip install requests

concept – 
For a given user profile, open view-source and find “profile_pic_url_hd” . To find press ctrl+f and type “profile_pic_url_hd” the link with it is our data or profile pic. 
The link will look like :


Below is the stepwise implementation of the project:

Step 1: import all dependence 


import requests
from bs4 import BeautifulSoup as bs
import json
import random
import os.path

Step 2: Ask for username and send a response to Instagram. 


inta_username= input('enter username of instagram : ')
response = requests.get(f"{insta_url}/{inta_username}/")

Step 3: if the response is ok, find profile photo link  

(Note: replace ‘\\u0026’ with ‘&’ in the string_url to remove bad URL timestamp or bad URL hash error)


if response.ok:
    bs_html=bs(html, features="lxml")
    print(string_url, "\n \n downloading..........")

Step 4: Now, create a loop and download photo. 


while True:
    filename='pic'+str(random.randint(1, 100000))+'.jpg'
    file_exists = os.path.isfile(filename)
    if not file_exists:
        with open(filename, 'wb+') as handle:
            response = requests.get(string_url, stream=True)
            if not response.ok:
            for block in response.iter_content(1024):
                if not block:
print("\n                downloading completed ..............")


Other Method : 
We can download profile pic of any Instagram account using instaloader module by just giving Instagram handle of the user.

First we need to install instaloader module :

pip install instaloader 



import instaloader
ig = instaloader.Instaloader()
dp = input("Enter Insta username : ")
ig.download_profile(dp , profile_pic_only=True)

Output :  Profile pic will be downloaded in  the same directory when we enter the input user id.

My Personal Notes arrow_drop_up
Last Updated : 16 Jun, 2022
Like Article
Save Article
Similar Reads
Related Tutorials