Get Instagram account details Using Python 2024

Introduction:

Get Instagram account details Using Python 2024 Get Instagram account details Using Python In this project, we will demonstrate how to use Python to retrieve any Instagram account details. This project is created with the Tkinter and instaloader package. Tkinter package allows for the quick and easy creation of GUI applications and instaloader package allows users to download Instagram content, including posts, stories, profile details, and more. This program has a straightforward design with an entry, a button, and labels.

Explanation:

This code creates a simple Tkinter-based GUI with an entry field to input the Instagram username and a button to fetch the account details. The fetched details will be displayed in a label below the button. his script uses instaloader to fetch the profile details for the specified username, such as username, full name, biography, follower count, following count, and the number of posts. It also handles the exceptions if any occurred.

1000+ Python Program PDF

Code Explanation

Sure, here’s a simplified explanation of what you did:

  1. Installed the Package: You used the command pip install instaloader to install a tool called Instaloader, which helps you get information from Instagram.
  2. Imported the Package: You made this tool available in your code by using the import instaloader command.
  3. Created a Loader Object: You made an instance of Instaloader, which is like creating a helper that will do the work for you.
  4. Got Username from User: You asked the user to provide an Instagram username by using the input() function.
  5. Fetched User Details: Using the username provided by the user, you used Instaloader’s Profile.from_username() method to get all available details about that Instagram profile.
  6. Displayed Results: Finally, you showed the fetched details on the screen.

Source Code:

import instaloader
import tkinter as tk

def fetch_account_details():
    username = username_entry.get()
    
    try:
        profile = instaloader.Profile.from_username(loader.context, username)
        
        details_label.config(text=f"Username: {profile.username}\n"
                                  f"Full Name: {profile.full_name}\n"
                                  f"Posts: {profile.mediacount}\n"
                                  f"Followers: {profile.followers}\n"
                                  f"Following: {profile.followees}\n"
                                  f"Bio: {profile.biography}\n"
                                  f"Links: {profile.external_url}\n"
                                  f"profile: {instaloader.Instaloader().download_profile(username,profile_pic_only=True)}"
                                  )

    except instaloader.exceptions.ProfileNotExistsException:
        details_label.config(text=f"The profile '{username}' does not exist.")
    except instaloader.exceptions.ConnectionException as e:
        details_label.config(text=f"Connection error: {e}")
    except instaloader.exceptions.QueryReturnedBadRequestException as e:
        details_label.config(text=f"Bad request error: {e}")
    except Exception as e:
        details_label.config(text=f"An error occurred: {e}")

# Create Instaloader instance
loader = instaloader.Instaloader()

# Create GUI window
root = tk.Tk()
root.title("Instagram Account Details")

# Username entry
username_label = tk.Label(root, text="Enter Username:")
username_label.pack()

username_entry = tk.Entry(root)
username_entry.pack()

# Fetch button
fetch_button = tk.Button(root, text="Fetch Details", command=fetch_account_details)
fetch_button.pack()

# Label to display details
details_label = tk.Label(root, text="", wraplength=300)
details_label.pack()

# Run the main loop
root.mainloop()


Get Instagram account details Using Python
Get Instagram account details Using Python

Leave a Comment