Join the top marketers who read our newsletter each week:

How to Download an Entire Account Instagram Posts and Stories with Python

Table of Contents

As much as the Archive feature of the Instagram app is useful, us Data Hoarders are often looking for a safer and more reliable way to archive our data. Whether it is because you want to keep your followers but start on a completely clean slate or because you want to make sure all of the posts and stories you published on the platform will always be accessible to you, I wanted to share the tools I use in order to archive Instagram accounts, including posts, highlights and even stories. I also use some of these tools in order to retrieve user-generated content after a contest or if I want to use the content generated in other platforms.

As usual, you will only need a basic knowledge of Python to perform these tasks and one library. You can also scroll through the article using the Table of Contents in order to reach the part of the tutorial that you are looking for. Ready? Let’s get into it.

Requirements

The first thing we want to do in order to move forward with this guide is install the Instaloader library. Originally a command-line program written in Python, this program obviously also has a Python module that we can load and use in our environments.

In order to install Instaloader, just “pip install instaloader” and you will be on your way.

From now on, all of your Python files for this tutorial should start with these lines:

If you are interested in this documentation and/or want to skip this tutorial and navigate yourself the code, you can do so by following this link: https://instaloader.github.io/as-module.html

How to Download a Single Instagram post, caption and comments with Python

Now that we are done with this first step, we can slowly get acclimated to the easiest things to do with this library.

In order to download a single post, or carousel or video, we need to get its ID first. To find a post’s ID, we just have to look at the URL of said post.

The highlighted part in this screenshot is the ID we want to copy.

Bring back this ID in the code shared below in your Python file:

Once run, you will discover that the beauty of this library is that it also downloads the comments and the caption related to the post in separate files as you can see below:

The argument “target” in the function “download_post()” is for you to define how the folder that the library will create to download the post in will be named. If the folder does not exist, the library will automatically create it but it won’t overwrite its content if the folder actually already exists.

How to Download Instagram Hashtag Posts with Python

Let’s say you are running a user-generated campaign and wish to download all of the posts that have been using the hashtag you asked your followers to use in their posts. Well, this library can help you with that.

In order to do so, simply run the code specified below:

As you can see, the only two parameters that are required are “hashtag” and “max_count”. The former is obviously required while the latter is optional. If you do not specify a maximum amount of posts you want to download, it will automatically try to download every single post found under the specified hashtag.

Once your command is done, you should end up with a folder named after your hashtag and all of the posts in it, filterable by date of publication:

How to Download Instagram Profile Highlights with Python

A neat feature of the library we are using here is its ability to circle through all of the highlights of someone’s profile and extracting the video file behind it. Because of the nature of the platform, we are going to need to log in through one of our Instagram accounts.

In order to do that, this is the code we are going to use:

Nothing more, nothing less. Now we can proceed with our highlights download by inputting this code into our script:

The only parameter you have to change is within the first line in the “from_username()” function. This is where you will want to input of which profile you want to download the highlights from.

Once this code is being run, you will see numerous folders being created where your script is located. Each folder represents one category of highlight. In the end, when downloading my girlfriend’s account’s highlights, this is what I ended up with:

How to Download Instagram Stories with Python

If you wish to save someone’s stories, this section is for you. If a user does not add a story to their highlights, you might have to act quickly and snatch up this story that you found yourself interested in using this script.

For this part to work, we also need to log in at the beginning of our script like in the above section, following this code:

Once this is done, we can proceed with this code:

This will create a pretty folder with all of the available stories of the user mentioned in the parameter “username” within the first line of code.

If all is right, you should end up with a folder similar to this one:

How to Download Saved Instagram Collections with Python

You might be afraid that one of the Instagram posts you’ve saved is going to get deleted or you just want to export your saved posts collections somewhere safe. Fortunately, it is pretty easy to do so. You only need to be logged in through the module like explained in the above section and run the following code:

As you can see, it is really easy and once this is finished, you should end up with your very own “/saved” directory where all of your saved posts will appear.

How to Download Entire Instagram Account’s Posts and Videos with Python

This section is one of the easiest in this article. Once you have installed and loaded the library, you can very easily proceed with extracting the entirety of the content posted by any public Instagram account online. If the account you are interested in is private, you will need to log in, using this code mentioned in the sections above:

If the account is public, be aware that the step depicted above is not necessary in order to follow through with the task at hand.

This is the code I am using to retrieve every single post, video and post carousel of any Instagram account:

This can take quite a while in the event of a very loaded profile but eventually, you will find yourself with an enormous amount of data such as:

  • .txt files with every caption for every post
  • .json files of comment threads for every post
  • .jpg files for every post, with the creation date being the actual published date
  • and a .jpg file for the Instagram account’s profile picture

All available for you to archive and/or analyze.

Conclusion

And that is pretty much it. I hope this has revealed itself useful to you and that this whole guide will help you overcome the challenge you have been facing. If it did help, I would love to hear about it in the comments or you can also email me 🙂 I would really appreciate it.

As usual, if you have any questions, feel free to shoot either by using the comments section down below so everyone can enjoy the answers or by email. Finally, if you’d like to see more tutorials of the sort, I can either suggest you read the same kind of guide I made around how to download Youtube Channels and Playlists with Python or subscribe to my newsletter using the form down below.

Thanks again for your time, see you around.

Join the top marketers who read our newsletter each week.

Yaniss Illoul

Share on twitter
Share on linkedin
Share on facebook
Share on reddit

You might also like these posts:

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

HELLO!

Get more tutorials, guides and curated content !

In your inbox, once a week.

wait!

Get more tutorials, guides and curated content !

In your inbox, once a week.