Javascript Instagram Scraper

J

scraper-instagram - npm

scraper-instagram – npm

Scrape data from Instagram without applying for the authenticated API.
Getting started
Prerequisites
NodeJS
NPM
Yarn
Install
From npm
yarn add scraper-instagram
or
npm i scraper-instagram –save
Test
git clone
yarn install or npm install
yarn test or npm run test
Optional environment variables for more complete testing:
SESSION_ID: a session ID for authentication test and authenticated tests
PUBLIC_PROFILE: a public profile to access
PRIVATE_PROFILE: a private profile to access
STORY_PROFILE_ID: a profile ID with a story to read
STORY_PROFILE_USERNAME: a profile username with a story to read
HASHTAG (default value: cat): a hashtag to fetch
LOCATION_ID (default value: 6889842 aka. Paris): a location to fetch
POST: a post to fetch
SEARCH_PROFILE: a profile to search for
SEARCH_HASHTAG (default value: cats): a hashtag to search for
SEARCH_LOCATION (default value: Paris): a location to search for
Methods not covered by tests:
subscribeUserPosts
subscribeHashtagPosts
subscribeAccountNotifications
Usage
const Insta = require(‘scraper-instagram’);
const InstaClient = new Insta();
Authentication
Authentication allows you to access private profile as long as you follow them.
Importing your session ID
Go to
Login (if not already logged in)
Open development tools (Ctrl + Shift + I)
Get the sessionid cookie value
For chromium-based browsers: application tab
For firefox-based browsers: storage tab
Code
thBySessionId(yourSessionId)
(account => (account))
(err => (err));
If authentication is successfull, you’ll get the form data from accounts/edit:
{
“first_name”: “”,
“last_name”: “”,
“email”: “”,
“is_email_confirmed”: true,
“is_phone_confirmed”: true,
“username”: “”,
“phone_number”: “”,
“gender”: 1,
“birthday”: null,
“biography”: “”,
“external_url”: “”,
“chaining_enabled”: true,
“presence_disabled”: false,
“business_account”: false,
“usertag_review_enabled”: false}
If your session ID is invalid, you’ll get the 401 error.
Username/password authentication may be supported in the future.
Get
These methods allows you to get specific elements from Instagram while you know exactly what you’re looking for.
Errors handling
get may return errors in the two following cases.
Request error: failed to get data from Instagram (HTTP code)
Parsing error: failed to parse data returned by Instagram (406)
No content: nothing to parse (204)
Authentication required: session ID required to access data (401)
Too many requests: rate limit exceeded (429)
Conflict: automation detected, password reset required (409)
Get profile by username
tProfile(username)
(profile => (profile))
Result
id string – Instagram identifier, only used for stories
name string – public full name
pic url – public profile picture
bio string – public biography
website url – public website
more info about bio & website
private boolean – account private state
access boolean – access to the profile’s feed
In order to have access to a private account’s feed, you must have sent him a follow request that he accepted.
verified boolean – account verified state
followers integer – number of users following this profile
following integer – number of users this profile follows
posts integer – number of posts this profile published
lastPosts array of posts – last posts
This property is empty ([]) when the profile doesn’t have any post but null if access is false (denied).
link url – link to the profile’s page
business string – business category (when applicable and profile unblocked)
user object – user relevant properties (while authenticated):
mutualFollowers array of usernames – people following you and this profile
blocking boolean – you blocked this profile
blocked boolean – this profile blocked you (only available property in user while true)
requesting boolean – you sent a follow request to this profile (if private)
requested boolean – this profile sent you a follow request (if yours is private)
following boolean – you’re following this profile
followed boolean – this profile follows you
Get profile story (requires authentication)
Using profile ID
tProfileStoryById(id)
Using profile username (will automatically request profile ID)
tProfileStory(username)
unread boolean – profile story is unread
author object – a subset of profile
username
pic
user object – user relevant properties
requesting
following
items array of stories – profile stories
url string – link to original story file (jpg, mp4,… )
type string – story type: photo or video
timestamp epoch
expirationTimestamp epoch
Those methods will return null when a profile has no story.
Note: calling this method will not mark the story as read.
Get hashtag
tHashtag(hashtag)
(hashtag => (hashtag))
pic url – hashtag profile pic (can’t find out how it is chosen)
posts integer – number of posts containing this hashtag
featuredPosts array of posts – featured posts published with this hashtag
lastPosts array of posts – last posts published with this hashtag
more info about hashtag posts
link url – link to the hashtag’s page
following boolean – you subscribed to this hashtag (receiving posts in your personal feed)
Get location by ID
Unfortunately, using IDs is currently the only way to get a location, at least for now.
tLocation(id)
(location => (location))
pic url – location profile pic
posts integer – posts published from that location
address object
street string
zipCode string
city string
latitude float
longitude float
website url – place’s website
phone string – place’s contact phone number
featuredPosts array of posts – featured posts published from this location
lastPosts array of posts – last posts published from this location
link url – link to this location’s page
Array of posts
This is a subset of a real post, containing the following properties:
shortcode string – post identifier
caption string – post description
comments integer – number of comments
likes integer – number of likes
thumbnail url – post thumbnail
Always static image wether it’s a photo or a video post, lower quality.
Get post by shortcode
The shortcode is the post’s identifier: the link to a post is
tPost(shortcode)
(post => (post))
author object – a subset of a profile’s properties.
username string
name string
pic url
verified boolean
link url
location
contents array of posts
type string – post type: photo or video
url string – link to original post file (jpg, mp4,… )
if type is video:
thumbnail string – link to thumbnail
views integer – number of views
tagged array of usernames – people tagged in post contents
hashtags array of hashtags – hashtags mentioned in post description
mentions array of usernames – people mentioned in post description
edited boolean – caption edited
comments array of objects (Max 40)
user string – comment author’s username
content string – comment content
hashtags array of hashtags
mentions array of usernames
likes integer
commentCount integer
link string – link to the post
Paginated getters (require authentication)
Paginated getters allows bulk data downloads.
Params:
maxCount integer – max number of items to return
pageId string (optional) – page navigation identifier
Result: array + nextPageId property
Sample:
(async () => {
const page0 = await somePaginatedGetter(someId, 50);
const page1 = await somePaginatedGetter(someId, 50, xtPageId);
const page2 = await somePaginatedGetter(someId, 50, xtPageId);})();
The pageId/nextPageId property may contain a string of digits, a base64 string, or a JSON string, but always must be leaved untouched.
Get profile posts
Result in array: full post object
tProfilePostsById(profileId, maxCount, pageId)
(posts => (posts))
tProfilePosts(profileUsername, maxCount, pageId)
Get post comments
tPostComments(shortcode, maxCount, pageId)
Result in array: comment object
Get hashtag posts
tHashtagPosts(hashtag, maxCount, pageId)
Result in array: partial post object
Get location posts
tLocationPostsById(locationId, maxCount, pageId)
Search
Search profile
archProfile(query)
(profiles => (profiles))
Result in array: a subset of profile.
name
private
verified
followers
user
Search hashtag
archHashtag(hashtag)
(hashtags => (hashtags))
Result in array: a subset of hashtag.
posts
Search location
archLocation(location)
(locations => (locations))
Result in array: a subset of location.
id
address
street
city
latitude
longitude
Subscribe to posts
options object (optional)
interval integer (optional) – time in seconds between requests. Default: 30
lastPostShortcode string (optional) – shortcode from which to begin if not the next one to be published.
fullPosts boolean (optional) – fetch full post data, additional request required
From user
bscribeUserPosts(username, (post, err) => {
if(post)
(ortcode);
else
(err);}, {
interval,
lastPostShortcode,
fullPosts});
From hashtag
bscribeHashtagPosts(hashtag, (post, err) => {
Account requests (user-relevant methods)
Get account notifications
tAccountNotifications()
(notifications => (notifications))
Result in array: notification
id string – Notification identifier
type string – Notification type: like, mention, comment, follow
post
shortcode
thumbnail
by
content string – Comment content (when applicable)
Subscribe to account notifications
lastNotificationId string (optional) – Notification ID
bscribeAccountNotifications((post, err) => {
lastNotificationId});
Get account stories
tAccountStories()
(stories => (stories))
Result in array: inbox-like
unread
Changelog
1. 0. 0 (2019-03-26) • Initial release
1. 1 (2019-03-27)
Fixed throw error scope
Fixed single photo post wrongly structured
Added support for comments
Added support for hashtags, mentions and tags in posts and comments
Added posts subscriptions feature from users (untested) and hashtags
1. 2 (2019-03-27) • Added support for videos
1. 4 (2019-03-27)
Fixed video post thumbnail & views count
Using promises & observable
1. 5 (2019-03-27) • Added proper error for private accounts
1. 6 (2019-03-31) • Private account access doesn’t require mutual follow
1. 7 (2019-04-03) • Added profile’s last posts analytics #1 + more
1. 8 (2019-04-14)
Using classes
Added support for authentication using session cookie (only allows to access friend profile)
Added support for locations
Added search feature for profiles, hashtags & locations
Added user-relevant properties
Added support for notifications history & subscription
Fixed subscriptions since #1
Removed useless id properties
1. 9
Added business property to profile (when applicable)
Automatically access public profile anonymously when user blocked
1. 10 (2020-01-26) • Fixed post comments on anonymous session
1. 11 (2020-04-18)
Improved subscriptions
Using async/await
Using simple callbacks instead of observables
Using object parameter for options
Added full post fetching option
Added subscription unsubscribe method
Improved 401 detection
Improved parsing
Using RegExp
Removed JSDOM dependency
Added support for edited post captions
1. 12 (2020-06-16) • Small fix & refactor
1. 13 (2020-07-10) • Added support for stories
1. 14 (2020-10-17) • Fixed access to own private profile
1. 15 (2020-12-19)
Removed Request dependency
Improved 429 detection
Added unit tests
1. 16 (2020-12-25)
Added full post commentCount property
Added partial post timestamp property
Added post comment id property
Added profile IDs memoization
Added getProfilePostsById & getProfilePosts methods
Added getPostComments method
Added getHashtagPosts method
Added getLocationPostsById method
Added 409 detection
Restored full post shortcode property
1. 17 (2021-01-2? )
Fixed error on empty profile story
Fixed 409 detection
Added profile story external link
2. 0 (202? -?? -?? )
Refactored names
Refactored scopes
Refactored promises
Refactored errors
Refactored indents
Renamed getLocation to getLocationById
Reverse subscribe methods post & error parameters
Improved unit tests coverage
Added JSDoc
IG | npm.io

IG | npm.io

Simple Instagram driver for Node. js0. 5. 8 • Published 6 years agoInstagram Private Web API client written in JS2. 2. 2 • Published 1 year agoInstagram scraper without authenticated API1. 0. 17 • Published 9 months agoLast 9 Photos: Instagram Widget of your Instagram Profile for your blog. Show latest 9 pics from your instagram account. (Unofficial Instagram Widget)2. 9. 0 • Published 7 months agocountry names by Alpha-2 country code in multiple languages1. 3 • Published 3 years agoA client to programmatically spreadbet with IG1. 3. 1 • Published 18 days agoGet user data and posts by scraping Instagram’s user page. Without API key or oAuth! 1. 1 • Published 14 days agoSimple Instagram driver for Node. js2. 0 • Published 5 years agoNodeJS tool to fetch Instagram analytics for any user without involving tokens or headless browsers. 4. 2 • Published 3 years agoCrawl the content of any instagram public page with no token or login0. 0 • Published 1 year agoNodeJS module NPM package that helps to scrap and load instagram profile media, posts comments and more useful information. 1. 11 • Published 1 year agoScrape instagram posts by username, shortcode, or hashtag1. 12 • Published 2 years agoA collection of helper functions to grab results from instadp. 5 • Published 1 year agoRetrieve Instagram user info. 0 • Published 3 years agoSimple Instagram driver for Node. 6. 0 • Published 4 years agoA React component for Instagram like stories for typescript1. 3 • Published 2 years agoMinimalistic wrapper around IG’s API0. 15. 0 • Published 4 years agoan instagram api that actually works2. 2 • Published 2 years agoSimple npm package for help you to scrapper instagram user1. 0 • Published 9 months agoInstagram Private Web API client written in JS2. 3 • Published 2 years ago
Instagram Scraper (Node.js) - GitHub

Instagram Scraper (Node.js) – GitHub

Scrapes an instagram user’s photos and videos. Use responsibly.
Usage
$ node
License
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to

Frequently Asked Questions about javascript instagram scraper

About the author

proxyreview

If you 're a SEO / IM geek like us then you'll love our updates and our website. Follow us for the latest news in the world of web automation tools & proxy servers!

By proxyreview

Recent Posts

Useful Tools