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
import instaloader
Imports the Instaloader library responsible for scraping Instagram media.from pathlib import Path
Used for clean directory handling and path management.enter_username = input("Enter username: ")
Takes username input from the user.DOWNLOAD_DIR = Path("/Users/satyamgajjar/Downloads") / f"{enter_username}"
Creates a folder inDownloadsnamed after the entered username.
Example:/Users/satyamgajjar/Downloads/shrenidubeyL = instaloader.Instaloader(download_videos=True)
Initializes Instaloader with video downloads enabled.DOWNLOAD_DIR.mkdir(parents=True, exist_ok=True)
Ensures the directory is created before download begins.profile = instaloader.Profile.from_username(L.context, enter_username)
Loads Instagram profile data.- Print Profile Info
Displays username, total posts, and privacy status. - 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
| Step | Action |
|---|---|
| 1 | Run the script |
| 2 | Enter Instagram username |
| 3 | Script creates folder automatically |
| 4 | All images + videos are saved locally |