Introduction to Instaloader module in Python
Last Updated :
27 Jan, 2023
The Instaloader module is a Python package having great functionalities to scrap instagram, it’s functions can be used as command-line utility. The Instaloader key is used to download:
- Posts of public/private account
- stories
- IGTV
- Comments on post
- Profile information
- Story highlights
The instaloader module can be used to download everything of profile/Instagram user, you need to interrupt by CONTROL+C to kill the process. However, for downloading files of a private account, you must log in, there is no compulsion for a public account. Also, comments are in json file which is zipped as a folder.
Installation:
pip install instaloader
Implementation:
Download everything about a profile:
instaloader geeks_for_geeks
On using this command your program will download everything about profiles. For public account, it will download stories, post, highlights news. For private, it only downloads profile photo and other public information about profile.
Output:
Download highlights of a particular profile:
instaloader –highlights geeks_for_geeks
Output:
The above command downloads public highlights of a particular profile
Download through Hashtag:
instaloader “#hashtag” coding_memes
Output:
The above command downloads posts having a given Hashtag.
Download IGTV videos
instaloader –igtv geeks_for_geeks
Output:
The above command is used to download videos of a particular profile on instagram in .mp4 format.
Profile class can be used to access metadata of profile
Python3
import instaloader
loader = instaloader.Instaloader()
loader.login(USER, PASSWORD)
profile = instaloader.Profile.from_username(loader.context,
'geeks_for_geeks' )
|
Attributes of Profile class:
followers
It returns the number of accounts following the given account
Python3
followers = profile.get_followers()
for follower in followers:
print (follower)
|
Output:
followees
It returns the number of accounts followed by given account
Python3
followees = profile.get_followees()
for followee in followees:
print (followee)
|
Output:
Number of followees of this profile
mediacount
It returns the total number of posts
Python3
media = profile.mediacount
print (media)
|
Output:
Total number of media count
igtvcount
It returns the total number of igtv posts
Python3
igtv = profile.igtvcount
print (igtv)
|
Output:
8
is_private
It tells whether account is private or not
Python3
private = profile.is_private
print (private)
|
Output:
False
biography
It returns the description/ bio of the account
Python3
bio = profile.biography
print (bio)
|
Output:
Biography of this profile using biography attributes
profile_pic_url
It returns the link to the profile picture of the account
Python3
profile_pic = profile.profile_pic_url
print (profile_pic)
|
Output:
Profile picture image url
external_url
It returns the external url (if any)
Python3
url = profile.external_url
print (url)
|
Output:
External link through Instagram
is_business_account
It tells whether the account is a business account or not
Python3
business = profile.is_business_account
print (business)
|
Output:
True
business_category_name
It returns the type of business account is associated with
Python3
business_type = profile.business_category_name
print (business_type)
|
Output:
Business category name of this profile
NOTE : Profile class objects have many more properties and functions to scrap Instagram profile metadata. A list of all the properties and functions of the Profile class object can be obtained using dir() function.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...