Python Instagram Scraper API SDK
Library - wrapper over instagrapi scraper API.
Used by API: https://rapidapi.com/fama-official-instagram-scraper/api/instagram-scraper-api2
This library provides basic data retrieval features with instagram: Users, Posts, Comments, etc. Read more below.
Warning:
It’s just a wrapper on the API. If the API stops working, the library stops working.
Quick Access:
Get Started
Available features:
- Get User info
- Get User medias with pagination
- Get User Followers with pagination
- Get Media Post info
- Get Media Post Comments with pagination
- Get Media Posts by Tagged user
- Get Media Posts by Hashtag
- Get Similar Users
- Search Users, Hashtags and Places
- Get Media Post Likes with pagination
Coming soon:
- Get User Following with pagination
- Get User Stories
- Get Story Info
- Get User Highlights
Installation:
Pre-requirements:
pip install scrapify-ig
Usage:
Use the client object to use all possible library functions. Create client object:
from scrapify_ig import Client
TOKEN = "<RapidAPI Token>"
client = Client(token=TOKEN)
Now you are ready to use the library.
Get user information:
See examples/user_info.md for more details
user_info = client.get_user_info(username_or_id_or_url="nike", include_about=False, url_embed_safe=False)
Get user media posts:
See examples/user_medias.md for more details
from scrapify_ig import types, exceptions
user_medias_chunk: types.MediaPostsChunk = client.get_user_medias_chunk(
username_or_id_or_url="nike",
url_embed_safe=False
)
next_user_medias_chunk: types.MediaPostsChunk = client.get_user_medias_chunk(
username_or_id_or_url="nike",
pagination_token=user_medias_chunk.pagination_token
)
next_users_medias_chunk: types.MediaPostsChunk = user_medias_chunk.next_chunk()
if user_medias_chunk.has_next_chunk():
next_users_medias_chunk: types.MediaPostsChunk = user_medias_chunk.next_chunk()
try:
next_users_medias_chunk: types.MediaPostsChunk = user_medias_chunk.next_chunk()
except exceptions.NoNextPageError:
pass
Get user followers:
from scrapify_ig import types
username = "nike"
user_followers_chunk: types.FollowersChunk = client.get_followers_chunk(username)
next_user_followers_chunk: types.FollowersChunk = client.get_followers_chunk(
username,
pagination_token=user_followers_chunk.pagination_token
)
next_user_followers_chunk: types.FollowersChunk = user_followers_chunk.next_chunk()
Get Media Post info:
See examples/media_info.md for more details
from scrapify_ig import types
media_identifier = "Cx8yen-uS-d"
media_info: types.MediaPost = client.get_media_info(
code_or_id_or_url=media_identifier,
url_embed_safe=False
)
Get Media Post Comments:
from scrapify_ig import types, exceptions
media_identifier = "Cx8yen-uS-d"
media_comments_chunk: types.CommentsChunk = client.get_media_comments_chunk(
code_or_id_or_url=media_identifier
)
if media_comments_chunk.has_next_chunk():
next_media_comments_chunk: types.CommentsChunk = media_comments_chunk.next_chunk()
some_comment_with_child: types.CommentsChunkItem = media_comments_chunk.data.items[6]
child_comments_chunk: types.CommentsThreadChunk = some_comment_with_child.get_comment_thread_chunk(client)
child_comments_chunk: types.CommentsThreadChunk = client.get_comment_thread_chunk(
comment_id=some_comment_with_child.id
)
if some_comment_with_child.has_thread_comments():
child_comments_chunk: types.CommentsThreadChunk = client.get_comment_thread_chunk(
comment_id=some_comment_with_child.id
)
try:
child_comments_chunk: types.CommentsThreadChunk = client.get_comment_thread_chunk(
comment_id=some_comment_with_child.id
)
except exceptions.HTTPNotFoundError:
pass
Get Media Posts by Tagged user:
from scrapify_ig import types
user_identifier = "nike"
tagged_posts_chunk: types.TaggedMediaPostsChunk = client.get_tagged_medias_chunk(
username_or_id_or_url=user_identifier
)
if tagged_posts_chunk.has_next_chunk():
next_tagged_posts_chunk: types.TaggedMediaPostsChunk = tagged_posts_chunk.next_chunk()
next_tagged_posts_chunk: types.TaggedMediaPostsChunk = client.get_tagged_medias_chunk(
username_or_id_or_url=user_identifier,
pagination_token=tagged_posts_chunk.pagination_token
)
Get Media Posts by Hashtag:
from scrapify_ig import types
hashtag = "nike"
hashtag_medias_chunk: types.MediaPostsHashtagChunk = client.get_medias_by_hashtag_chunk(
hashtag=hashtag
)
if hashtag_medias_chunk.has_next_chunk():
next_hashtag_medias_chunk: types.MediaPostsHashtagChunk = hashtag_medias_chunk.next_chunk()
next_hashtag_medias_chunk: types.MediaPostsHashtagChunk = client.get_medias_by_hashtag_chunk(
hashtag=hashtag,
pagination_token=hashtag_medias_chunk.pagination_token
)
Get Similar Users:
from scrapify_ig import types
user_identifier = "nike"
similar_accounts: types.SimilarAccounts = client.get_similar_accounts(
username_or_id_or_url=user_identifier
)
Search Users, Hashtags and Places:
from scrapify_ig import types
search_query = "London"
search_result: types.SearchResult = client.search(search_query=search_query)
Get Media Post Likes with pagination:
from scrapify_ig import types
media_identifier = "Cx8yen-uS-d"
media_likes_chunk: types.LikesMediaPostsChunk = client.get_media_likes_chunk(
code_or_id_or_url=media_identifier
)
if media_likes_chunk.has_next_chunk():
media_likes_chunk: types.LikesMediaPostsChunk = media_likes_chunk.next_chunk()
Types:
- user scrapify_ig.types for better typing. Also in this module you can see all available fields for each object
Errors and Issues:
If you notice an error or problem, please write about it here https://gitlab.com/oleksii.stulen.public/scrapify-ig/issues. Describe the problem as precisely as possible. What did you do, what did you want to get, how did you do it and so on. Thank you!
Author: Oleksii Stulen
Email: oleksii.stulen.workspace@gmail.com