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
import instaloader
# Get instance loader = instaloader.Instaloader()
# Login using the credentials loader.login(USER, PASSWORD) # Use Profile class to access metadata of account 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
# returns iterator to list of followers of given profile followers = profile.get_followers()
for follower in followers:
print (follower)
|
Output:
followees
It returns the number of accounts followed by given account
# returns iterator to list of followees # (followings) of given profile followees = profile.get_followees()
for followee in followees:
print (followee)
|
Output:
mediacount
It returns the total number of posts
# returns an integer representing number of posts media = profile.mediacount
print (media)
|
Output:
igtvcount
It returns the total number of igtv posts
# returns integer equal to the number of igtv posts igtv = profile.igtvcount
print (igtv)
|
Output:
8
is_private
It tells whether account is private or not
# returns a bool object private = profile.is_private
print (private)
|
Output:
False
biography
It returns the description/ bio of the account
# returns bio of the profile bio = profile.biography
print (bio)
|
Output:
profile_pic_url
It returns the link to the profile picture of the account
# returns link to the profile picture profile_pic = profile.profile_pic_url
print (profile_pic)
|
Output:
external_url
It returns the external url (if any)
# returns external url if it is present in the profile url = profile.external_url
print (url)
|
Output:
is_business_account
It tells whether the account is a business account or not
# returns a bool object business = profile.is_business_account
print (business)
|
Output:
True
business_category_name
It returns the type of business account is associated with
# returns the business category business_type = profile.business_category_name
print (business_type)
|
Output:
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.