Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 Instaloader Script to Download Instagram Profile Posts ,Images and Videos Using Username in Command Line

Posted on January 16, 2023

 

 

Welcome folks today in this blog post we will be downloading instagram profile posts,images and videos using username in command line using instaloader library in python. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to install the below library using the pip command as shown below

 

 

pip install instaloader

 

 

And after this you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

Python
1
2
3
4
5
6
7
import instaloader
 
# Initialize Instaloader
L = instaloader.Instaloader()
 
# Specify the profile username
username = "blackcapsnz"

 

 

 

As you can see we are importing the instaloader library and then we are using the Instaloader() method and then we are declaring the username from which we need to download the posts.

 

 

Python
1
2
3
4
5
6
7
# Download the profile's posts
profile = instaloader.Profile.from_username(L.context, username)
for post in profile.get_posts():
    L.download_post(post, target=username)
 
# Close the Instaloader session
L.context.close()

 

 

As you can see we are fetching all the instagram posts from the username using the from_username() method and here we are passing the context and also we are passing the username and then for each post we are downloading it for this we are using the for loop and for downloading it we are using the download_post() method. And inside it we are passing the actual post and the target username. And after that we are closing the instaloader session using the close() method. Now if you execute the python script you will see the below result.

 

 

 

 

As you can see it has created the blackcapsnz directory once you run the python script and it contains all the posts images and videos successfully downloaded.

 

Recent Posts

  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Android Java Project to Download Youtube Video Thumbnail From URL & Save it inside SD Card
  • Android Java Project to Embed Google Maps & Add Markers Using Maps SDK
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme