Instagram osint with Instaloader

Introduction to Instaloader



Instaloader is an open-source tool written in Python that can help automate the intelligence-gathering process on Instagram. As a command line utility, it comes with many flags. It can download the whole posts of a target, its stories, highlights, IGTV media, and even the tagged content.  


For each post and media downloaded Instaloader saves metadata as a compressed JSON file by default. The --no-compress-json switch can be used to stop compressing the metadata.


A feature that has proven to be very useful to me is the ability to download Instagram content based on a specific hashtag. The Instagram API rate limit may be triggered when receiving information based on a hashtag. According to the official documentation, Instaloader goes to sleep to avoid bot detection from Instagram.


Time sleep during intelligence gathering with instaloader



As for the file structure and naming of the downloaded content, the user has three flags out of the box. Although the defaults work fine, it is always a good idea to keep your environment organized and clean. 

An advanced user has all the tools to write custom scripts for complex use cases. Some code examples are provided through the official documentation.


How to install Instaloader


One can use Instaloader in two ways: install it as a package via the Python package installer or run it as a script in a virtual environment. 


To install Instaloader via pip type:


pip install instaloader


Run Instaloader as a script.


To download the source code type:


wget -O instaloader.zip https://shorturl.at/gtu25


To create a virtual environment type:


python -m venv env


To activate the virtual environment type:


env\Script\activate


To run instaloader type:


python instaloader.py --help



Open-source intelligence gathering with Instaloader


To download the posts from a public profile type:


python instaloader.py --dirname-pattern="C:\Users\User\Desktop\linuxosint\{profile}" itsfoss


As you can see the --dirname-pattern creates the tree structure for the content to be stored. In this case, the {profile} syntax is replaced by the target, the itsfoss username.


To avoid the creation of text files for captions type:


python instaloader.py --no-captions --dirname-pattern="C:\Users\User\Desktop\linuxosint\{profile}" itsfoss


To avoid the download of videos type:


python instaloader.py --no-videos --dirname-pattern="C:\Users\User\Desktop\linuxosint\{profile}" itsfoss


Instaloader downloads the whole images of a sidecar by default. To specify the range use the --slide option shown below:


python instaloader.py --slide 1-4 --dirname-pattern="C:\Users\User\Desktop\linuxosint\{profile}" itsfoss


To download the tagged content type:


python instaloader.py --no-posts --tagged --dirname-pattern="C:\Users\User\Desktop\linuxosint\{profile}\tagged" itsfoss


To download the IGTV content type:


python instaloader.py --no-posts --igtv --dirname-pattern="C:\Users\User\Desktop\linuxosint\{profile}\igtv" itsfoss



Information that requires login


Instaloader supports login to Instagram with the --login option. Once it has successfully authenticated it saves a cookie session file in a local directory that can be used for login to Instagram the next time.

Due to some errors, I experienced with the --login and --password flags, I managed to log in through an official workaround published in the original repository of Instaloader.

Log in to Instagram using Firefox. 

Download the script that can be used to fetch the session from Firefox and place it in the instaloader directory.



To run the script type:


python 615_import_firefox_session.py


The execution of the above script imports the cookie session from Firefox and saves it to the local directory.


To login type:


python instaloader.py --login orthodox.pirate # orthodox.pirate is the username 


To download only the stories type:


python instaloader.py --login orthodox.pirate --no-posts --stories --dirname-pattern="C:\Users\User\Desktop\linuxosint\{profile}\stories" itsfoss


The flag --no-posts is important as by default Instaloader downloads posts.


To download only the highlights of a profile type:


python instaloader.py --login orthodox.pirate --no-posts --highlights --dirname-pattern="C:\Users\User\Desktop\linuxosint\{profile}\highlights" itsfoss



If available, geotags can be downloaded:


python instaloader.py --login orthodox.pirate --geotags --dirname-pattern="C:\Users\User\Desktop\linuxosint\{profile}" itsfoss


Instaloader resumes where it left when the process of downloading is interrupted. The flag --no-resume can be used to not resume a previously aborted iteration.

python instaloader.py --no-resume --dirname-pattern="C:\Users\User\Desktop\linuxosint\{profile}" itsfoss


To specify a custom User-Agent type:


python instaloader.py --user-agent "Python-Tool" --dirname-pattern="C:\Users\User\Desktop\linuxosint\{profile}" itsfoss


To download based on a hashtag type:


python instaloader.py --login orthodox.pirate #linux 


Multiple hashtags can be specified. 


python instaloader.py --login orthodox.pirate #linuxitalia #pythonitalia


To download the followees of a profile type:


python instaloader.py --login orthodox.pirate @itsfoss


The above command downloads every Instagram profile followed by the user itsfoss.


Scripting with Instaloader


There may be times when the available command line options don't meet your requirements. Having a knowledge of Python, you can write your own custom scripts that make use of tools provided by Instaloader.

There is no flag that can be used to retrieve the followers of a profile. The method get_followers() can be called in a script to fetch information about followers of an Instagram profile.

The following is a script I have coded with the primary purpose of gathering information on followers of an Instagram profile. It retrieves information about the username, full name, whether the profile is private or not, the URL of the profile's picture, and also the biography of the person if available.




Another script I have coded checks the content for a sidecar. It is useful when gathering information on Instagrammers who share their expertise on a specific topic. Every time I want to learn about new computer technologies or new tools I launch this script.


Final thoughts 


Instaloader is a very effective tool when it comes to open-source intelligence gathering on Instagram. Whether one is interested in single profiles or heavy osint, Instaloader is a key utility. Not only is it rich in features, but it also manages to avoid Instagram's bot detection mechanisms. 

Although there is always something to fix and improve, with an average knowledge of Python a user can manage to satisfy all their needs.

Note: This article is a work in progress, there will be frequent updates to it.

© 2023 Copyright by orthodoxpirate.blogspot.com
All Rights Reserved

No comments

Powered by Blogger.