Download Instagram Posts

Introduction

This Python script uses Instaloader to download all posts from a public Instagram account. It automatically creates a folder using the Instagram username and stores all downloaded images and videos inside it.

This tool is helpful for:
✔ Bulk content download
✔ Dataset creation for ML/AI projects
✔ Personal content archiving
✔ Offline media storage


Code Explanation

  1. import instaloader
    Imports the Instaloader library responsible for scraping Instagram media.
  2. from pathlib import Path
    Used for clean directory handling and path management.
  3. enter_username = input("Enter username: ")
    Takes username input from the user.
  4. DOWNLOAD_DIR = Path("/Users/satyamgajjar/Downloads") / f"{enter_username}"
    Creates a folder in Downloads named after the entered username.
    Example: /Users/satyamgajjar/Downloads/shrenidubey
  5. L = instaloader.Instaloader(download_videos=True)
    Initializes Instaloader with video downloads enabled.
  6. DOWNLOAD_DIR.mkdir(parents=True, exist_ok=True)
    Ensures the directory is created before download begins.
  7. profile = instaloader.Profile.from_username(L.context, enter_username)
    Loads Instagram profile data.
  8. Print Profile Info
    Displays username, total posts, and privacy status.
  9. Download all Posts for post in profile.get_posts(): L.download_post(post, target=str(DOWNLOAD_DIR)) Loops through all posts and downloads each one.


Steps to Use

StepAction
1Run the script
2Enter Instagram username
3Script creates folder automatically
4All images + videos are saved locally
Share this post:
Facebook
Twitter
LinkedIn

Web Development Projects

Interested in more? Check out my Machine Learning projects as well.

Machine Learning Projects

Interested in more? Check out my Machine Learning projects as well.

Python Projects

Interested in more? Check out my Python projects as well.