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
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
.
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.