Package: instagramy
InstagramyPython Package for Instagram Without Any external dependenciesScrape Instagram Users Information, Posts data, Hashtags and Locations data. This Package scrapes the user's recent posts with some information like likes, comments, captions and etc. No external dependencies.FeaturesIt scrapes most of the data ofInstagram user,hastags,PostsandLocationYou can use this packagewith loginorwithout loginDownloadInstagram postandUser profile pictureHave somepluginsfor Data analysisNo External dependenciesHavingcaching FunctionLightweightEasy to UseDownloadInstallationpipinstallinstagramyDev Versionpipinstallgit+https://github.com/yogeshwaran01/instagramy.gitUpgradepipinstallinstagramy--upgradeSample UsageGetting Session Id of InstrgramFor Login into Instagram via instagramy session id is required. No username or password is Needed. You must be login into Instagram via Browser to get session idLogin into Instagram in default webbrowserMove to Developer optionCopy the sessionidMove to storage and then to cookies and copy the sessionid (Firefox)Move to Application and then to storage and then to cookies and copy the sessionid (Chrome)Note:Check for session id frequently, It may be changed by InstagramInstagram User detailsClassInstagramUserscrape some of the information related to the user of the Instagram>>>frominstagramyimportInstagramUser>>>session_id="38566737751%3Ah7JpgePGAoLxJe%334">>>user=InstagramUser('google',sessionid=session_id)>>>user.is_verifiedTrue>>>user.biography'Google unfiltered—sometimes with filters.'>>>user.user_data# More data about user as dictIf you get the data of the user onetime, instagramy store the data as cache file for avoid the error. you can get the data from cache also. Don't provide the sessionid.>>>frominstagramyimportInstagramUser>>>user=InstagramUser('google',from_cache=True)>>>user.is_verifiedTrueIt is opt of all classesInstagramUser,InstagramHashTagandInstagramPost.Show all Propertiesbiographyconnected_fb_pagefollowed_by_viewerfollows_viewerfullnamehas_blocked_viewerhas_country_blockhas_requested_vieweris_blocked_by_vieweris_joined_recentlyis_privateis_verifiedno_of_mutual_followernumber_of_followersnumber_of_followingsnumber_of_postsother_infopostsposts_display_urlsprofile_picture_urlrequested_by_viewerrestricted_by_viewerusernamewebsiteInstagramUser.user_datahas more data other than defined asPropertiesInstagram Hashtag detailsClassInstagramHashTagscrape some of the information related to the hash-tag of the Instagramyou can also set your sessionid as env variable$exportSESSION_ID="38566737751%3Ah7JpgePGAoLxJe%er40q">>>importos>>>frominstagramyimportInstagramHashTag>>>session_id=os.environ.get("SESSION_ID")>>>tag=InstagramHashtag('google',sessionid=session_id)>>>tag.number_of_posts9556876>>>tag.tag_data# More data about hashtag as dictShow all Propertiesnumber_of_postsposts_display_urlsprofile_pic_urltagnametop_postsInstagramHashTag.tag_datahas more data other than defined asPropertiesInstagram Post detailsClassInstagramPostscrape some of the information related to the particular post of Instagram. It takes the post id as the parameter. You can get the post id from the URL of the Instagram posts from the property ofInstagramUser.posts. orInstagramHagTag.top_posts>>>frominstagramyimportInstagramPost>>>session_id="38566737751%3Ah7JpgePGAoLxJe%334">>>post=InstagramPost('CLGkNCoJkcM',sessionid=session_id)>>>post.author'ipadpograffiti'>>>post.number_of_likes1439>>>post.post_data# More data about post as dictShow all Propertiesauthorcaptiondisplay_urlget_jsonnumber_of_commentsnumber_of_likespost_sourcetexttype_of_postupload_timeInstagramPost.post_datahas more data other than defined asPropertiesInstagram Location detailsClassInstagramLocationscrape some of the information and posts related to the given Location . It takes the location id and slug as the parameter. You can get the location id and slug from the URL of the Instagram Location or from the property ofInstagramPost.location.idandInstagramPost.location.slug.>>>frominstagramyimportInstagramPost>>>session_id="38566737751%3Ah7JpgePGAoLxJe%334">>>post=InstagramPost('CLGkNCoJkcM',sessionid=session_id)>>>location_id,slug=post.location.id,post.location.slug>>>fromInstagramyimportInstagramLocation>>>location=InstagramLocation(location_id,slug,session_id)>>>location.latitude28.6139>>>location.longitude77.2089>>>location.address{'street_address':'T2, Indira Gandhi International Airport','zip_code':'','city_name':'New Delhi','region_name':'','country_code':'IN','exact_city_match':False,'exact_region_match':False,'exact_country_match':False}you can also get the location id and slug from the instagram urlhttps://www.instagram.com/explore/locations/977862530/mrc-nagar
https://www.instagram.com/explore/locations/<location_id>/<slug>Show all Propertiesaddressidlatitudelocation_datalongitudenamenumber_of_postsphoneprofile_pic_urlsessionidslugtop_postsurlviewerwebsiteInstagramLocation.location_datahas more data other than defined asPropertiesPluginsInstagramy has some plugins for easePlugins for Data Analyzinganalyze_users_popularityanalyze_hashtagsanalyze_user_recent_posts>>>importpandasaspd>>>frominstagramy.plugins.analysisimportanalyze_users_popularity>>>session_id="38566737751%3Ah7JpgePGAoLxJe%334">>>teams=["chennaiipl","mumbaiindians","royalchallengersbangalore","kkriders","delhicapitals","sunrisershyd","kxipofficial"]>>>data=analyze_users_popularity(teams,session_id)>>>pd.Dataframe(data)UsernamesFollowersFollowingPosts0chennaiipl618929219456461mumbaiindians6244961124121172royalchallengersbangalore54300185982523kkriders22047396879914delhicapitals20975157595225sunrisershyd20538247062276kxipofficial1884241677496Plugins for Downloading Postsdownload_hashtags_postsdownload_postdownload_profile_pic>>>importos>>>frominstagramy.plugins.downloadimport*>>>session_id=os.environ.get('SESSION_ID')>>>download_profile_pic(username='google',sessionid=session_id,filepath='google.png')>>>download_post(id="ipadpograffiti",sessionid=session_id,filepath='post.mp4')>>>download_hashtags_posts(tag="tamil",session_id=session_id,count=2)Use Without LoginYou can use this package without login. Sessionid is not required but it may riseRedirectionErrorerror after four to five requests.>>>frominstagramyimport*>>>user=InstagramUser('google')>>>user.fullname'Google'>>>tag=InstagramHashTag('python')>>>tag.tag_dataCaching Featurefrom version4.3, Added the new feature that is caching the required data. If you get the data of the user onetime, instagramy store the data as cache json file for avoid the error. you can get the data from cache also. Don't need to provide the sessionid. Instead of sessionid add the optional parameterfrom_cache=True.>>>frominstagramyimportInstagramUser>>>user=InstagramUser('google',from_cache=True)>>>user.is_verifiedTrueIt is opt of all classesInstagramUser,InstagramHashTag,InstagramPostandInstagramLocation.Clear all Caches created by instagramy in current dir by>>>frominstagramy.core.cacheimportclear_caches>>>clear_caches()# clear all caches of instagramyList of all Cache files created by instagramy in current dir>>>frominstagramyimportlist_caches>>>list_caches()# list all caches of instagramySample ScriptsGetting Email address and phone numberuser=InstagramUser('username')email,phone_number=user.user_data['business_email'],user.user_data['business_phone_number']✏️ Important NotesDon't send huge request to Instagram with sessionid, Instagram may ban you.You can use this package without sessionid (Login). But it mayRedirectionErrorafter four to five requests.classViewerprovide the data about currently logged in user.Check for session id frequently, It may be changed by InstagramIf code execution is never gets completed, check and change your session id and try again.Don't provide the wrong session_id.InstagramUser.user_data,InstagramPost.post_data,InstagramHashtag.tag_dataandInstagramLocation.location_datawhich is pythondicthas more and more data other than defined asProperties.This Package does not scrap all the posts from an account, the limit of the post only 12 (For non-private account)This Package not scrap all the posts of given hash-tag and location it only scrapes the top 60 - 72 posts.DisclaimerIf you send the huge request to the Instagram with session id Instagram may ban you. I am not responsible for any misuse or damage caused by this program.LicenseMIT LicenseContributionsContributions are Welcome. Feel free to report bugs inissueand fix some bugs by creatingpull requests. Comments, Suggestions, Improvements and Enhancements are always welcome. Let disscuss about itHere.Made with Python ❤️