scrape-insta v1.0.20
scrape-insta
Mengikis data dari Instagram tanpa mendaftar ke API yang diautentikasi. By FRM Developer dari scraper-instagram
Getting started
Prerequisites
- NodeJS
- NPM
- Yarn
Install
DARI npm
masukkan tulisan dibawah ke package.json
"scrape-insta": "latest"
atau ketik di terminal / command prompt
npm install scrape-insta
Variabel lingkungan opsional untuk pengujian yang lebih lengkap:
SESSION_ID: ID sesi untuk uji autentikasi dan uji autentikasiPUBLIC_PROFILE: profil publik untuk diaksesPRIVATE_PROFILE: profil pribadi untuk diaksesSTORY_PROFILE_ID: ID profil dengan cerita untuk dibacaSTORY_PROFILE_USERNAME: nama pengguna profil dengan cerita untuk dibacaHASHTAG(default value :cat) : tagar untuk diambilLOCATION_ID(default value :6889842aka. Paris) : lokasi untuk diambilPOST: sebuah pos untuk diambilSEARCH_PROFILE: profil untuk dicariSEARCH_HASHTAG(default value :cats) : hashtag untuk mencariSEARCH_LOCATION(default value :Paris) : lokasi untuk mencari
Metode yang tidak tercakup oleh tes:
subscribeUserPostssubscribeHashtagPostssubscribeAccountNotifications
Penggunaan
const Insta = require('scrape-insta');
const InstaClient = new Insta();Otentikasi
Otentikasi memungkinkan Anda untuk mengakses profil pribadi selama Anda mengikuti mereka.
Mengimpor ID sesi Anda dengan desktop
- Buka instagram.com
- Login (jika belum login)
- Open development tools (
Ctrl+Shift+I) - Ambil
sessionidcookie value - Untuk browser berbasis chromium :applicationtab - Untuk browser berbasis firefox :storagetab
Mengimpor ID sesi Anda dengan Android
- Buka instagram.com di browser
- Login (jika belum login)
- Buka aplikasi HTTP Canary dan aktifkan pemantauan
- Buka browser dan kunjungi instagram.com
- Buka HTTP Canary dan hentikan pemantauan
- Cari instagram.com di http canary dan cari cookie
Code
InstaClient.authBySessionId(yourSessionId)
.then(account => console.log(account))
.catch(err => console.error(err));Jika otentikasi berhasil, Anda akan mendapatkan data formulir dari 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
}Jika ID sesi Anda tidak valid, Anda akan mendapatkan 401 error.
Otentikasi nama pengguna/kata sandi mungkin didukung di masa mendatang.
Get
Metode ini memungkinkan Anda untuk mendapatkan elemen tertentu dari Instagram sementara Anda tahu persis apa yang Anda cari.
Errors handling
get dapat mengembalikan kesalahan dalam dua kasus berikut.
- 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)
Dapatkan profil berdasarkan nama pengguna
InstaClient.getProfile(username)
.then(profile => console.log(profile))
.catch(err => console.error(err));Result
idstring - Instagram identifier, only used for storiesnamestring - public full namepicurl - public profile picturebiostring - public biographywebsiteurl - public website more info about bio & websiteprivateboolean - account private stateaccessboolean - 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.verifiedboolean - account verified statefollowersinteger - number of users following this profilefollowinginteger - number of users this profile followspostsinteger - number of posts this profile publishedlastPostsarray of posts - last posts This property is empty ([]) when the profile doesn't have any post butnullifaccessisfalse(denied).linkurl - link to the profile's pagebusinessstring - business category (when applicable and profile unblocked)userobject - user relevant properties (while authenticated) : -mutualFollowersarray of usernames - people following you and this profile -blockingboolean - you blocked this profile -blockedboolean - this profile blocked you (only available property inuserwhiletrue) -requestingboolean - you sent a follow request to this profile (if private) -requestedboolean - this profile sent you a follow request (if yours is private) -followingboolean - you're following this profile -followedboolean - this profile follows you
Get profile story (requires authentication)
Using profile ID
InstaClient.getProfileStoryById(id)
.then(profile => console.log(profile))
.catch(err => console.error(err));Using profile username (will automatically request profile ID)
InstaClient.getProfileStory(username)
.then(profile => console.log(profile))
.catch(err => console.error(err));Result
unreadboolean - profile story is unreadauthorobject - a subset of profileusernamepic
userobject - user relevant propertiesrequestingfollowing
itemsarray of stories - profile storiesurlstring - link to original story file (jpg,mp4, ...)typestring - story type :photoorvideotimestampepochexpirationTimestampepoch
Those methods will return null when a profile has no story.
Note : calling this method will not mark the story as read.
Get hashtag
InstaClient.getHashtag(hashtag)
.then(hashtag => console.log(hashtag))
.catch(err => console.error(err));Result
picurl - hashtag profile pic (can't find out how it is chosen)postsinteger - number of posts containing this hashtagfeaturedPostsarray of posts - featured posts published with this hashtaglastPostsarray of posts - last posts published with this hashtag more info about hashtag postslinkurl - link to the hashtag's pageuserobject - user relevant properties (while authenticated) : -followingboolean - 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.
InstaClient.getLocation(id)
.then(location => console.log(location))
.catch(err => console.error(err));Result
picurl - location profile picpostsinteger - posts published from that locationaddressobject -streetstring -zipCodestring -citystring -latitudefloat -longitudefloatwebsiteurl - place's websitephonestring - place's contact phone numberfeaturedPostsarray of posts - featured posts published from this locationlastPostsarray of posts - last posts published from this locationlinkurl - link to this location's page
Array of posts
This is a subset of a real post, containing the following properties :
shortcodestring - post identifiercaptionstring - post descriptioncommentsinteger - number of commentslikesinteger - number of likesthumbnailurl - 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 instagram.com/p/shortcode.
InstaClient.getPost(shortcode)
.then(post => console.log(post))
.catch(err => console.error(err));Result
authorobject - a subset of a profile's properties. -usernamestring -namestring -picurl -verifiedboolean -linkurllocation-namestring -citystringcontentsarray of posts -typestring - post type :photoorvideo-urlstring - link to original post file (jpg,mp4, ...) - iftypeisvideo:thumbnailstring - link to thumbnailviewsinteger - number of viewstaggedarray of usernames - people tagged in post contentslikesinteger - number of likescaptionstring - post descriptionhashtagsarray of hashtags - hashtags mentioned in post descriptionmentionsarray of usernames - people mentioned in post descriptioneditedboolean - caption editedcommentsarray of objects (Max 40) -userstring - comment author's username -contentstring - comment content -timestampepoch -hashtagsarray of hashtags -mentionsarray of usernames -likesintegercommentCountintegertimestampepochlinkstring - link to the post
Paginated getters (require authentication)
Paginated getters allows bulk data downloads.
Params :
maxCountinteger - max number of items to returnpageIdstring (optional) - page navigation identifier
Result : array + nextPageId property
Sample :
(async () => {
const page0 = await somePaginatedGetter(someId, 50);
const page1 = await somePaginatedGetter(someId, 50, page0.nextPageId);
const page2 = await somePaginatedGetter(someId, 50, page1.nextPageId);
})();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
Using profile ID
InstaClient.getProfilePostsById(profileId, maxCount, pageId)
.then(posts => console.log(posts))
.catch(err => console.error(err));Using profile username (will automatically request profile ID)
InstaClient.getProfilePosts(profileUsername, maxCount, pageId)
.then(posts => console.log(posts))
.catch(err => console.error(err));Get post comments
InstaClient.getPostComments(shortcode, maxCount, pageId)
.then(posts => console.log(posts))
.catch(err => console.error(err));Result in array : comment object
Get hashtag posts
InstaClient.getHashtagPosts(hashtag, maxCount, pageId)
.then(posts => console.log(posts))
.catch(err => console.error(err));Result in array : partial post object
Get location posts
InstaClient.getLocationPostsById(locationId, maxCount, pageId)
.then(posts => console.log(posts))
.catch(err => console.error(err));Result in array : partial post object
Search
Search profile
InstaClient.searchProfile(query)
.then(profiles => console.log(profiles))
.catch(err => console.error(err));Result in array : a subset of profile.
usernamenamepicprivateverifiedfollowersuser-following
Search hashtag
InstaClient.searchHashtag(hashtag)
.then(hashtags => console.log(hashtags))
.catch(err => console.error(err));Result in array : a subset of hashtag.
nameposts
Search location
InstaClient.searchLocation(location)
.then(locations => console.log(locations))
.catch(err => console.error(err));Result in array : a subset of location.
idnameaddress-street-city-latitude-longitude
Subscribe to posts
optionsobject (optional)intervalinteger (optional) - time in seconds between requests. Default : 30lastPostShortcodestring (optional) - shortcode from which to begin if not the next one to be published.fullPostsboolean (optional) - fetch full post data, additional request required
From user
InstaClient.subscribeUserPosts(username, (post, err) => {
if(post)
console.log(post.shortcode);
else
console.error(err);
}, {
interval,
lastPostShortcode,
fullPosts
});From hashtag
InstaClient.subscribeHashtagPosts(hashtag, (post, err) => {
if(post)
console.log(post.shortcode);
else
console.error(err);
}, {
interval,
lastPostShortcode,
fullPosts
});Account requests (user-relevant methods)
Get account notifications
InstaClient.getAccountNotifications()
.then(notifications => console.log(notifications))
.catch(err => console.error(err));Result in array : notification
idstring - Notification identifiertimestampepochtypestring - Notification type :like,mention,comment,followpost-shortcode-thumbnailby-username-name-piccontentstring - Comment content (when applicable)
Subscribe to account notifications
optionsobject (optional)intervalinteger (optional) - time in seconds between requests. Default : 30lastNotificationIdstring (optional) - Notification ID
InstaClient.subscribeAccountNotifications((post, err) => {
if(post)
console.log(post.shortcode);
else
console.error(err);
}, {
interval,
lastNotificationId
});Get account stories
InstaClient.getAccountStories()
.then(stories => console.log(stories))
.catch(err => console.error(err));Result in array : inbox-like
unreadauthorobject - a subset of a profile's properties.idusernamepic
userobject - user relevant propertiesrequestingfollowing
Changelog
1.0.0(2019-03-26) • Initial release1.0.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 hashtags1.0.2(2019-03-27) • Added support for videos1.0.4(2019-03-27) - Fixed video post thumbnail & views count - Using promises & observable1.0.5(2019-03-27) • Added proper error for private accounts1.0.6(2019-03-31) • Private account access doesn't require mutual follow1.0.7(2019-04-03) • Added profile's last posts analytics #1 + more1.0.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 uselessidproperties1.0.9- Addedbusinessproperty to profile (when applicable) - Automatically access public profile anonymously when user blocked1.0.10(2020-01-26) • Fixed post comments on anonymous session1.0.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
401detection - Improved parsing
- Using RegExp
- Removed JSDOM dependency
- Added support for edited post captions
- Improved subscriptions
1.0.12(2020-06-16) • Small fix & refactor1.0.13(2020-07-10) • Added support for stories1.0.14(2020-10-17) • Fixed access to own private profile1.0.15(2020-12-19) - Removed Request dependency - Improved429detection - Added unit tests1.0.16(2020-12-25)- Added full post
commentCountproperty - Added partial posttimestampproperty - Added post commentidproperty - Added profile IDs memoization - Added
getProfilePostsById&getProfilePostsmethods - Added
getPostCommentsmethod - Added
getHashtagPostsmethod - Added
getLocationPostsByIdmethod - Added409detection - Improved
401detection - Restored full postshortcodeproperty
- Added full post
1.0.17(2021-01-21) - Fixed error on empty profile story- Fixed
409detection- Added profile story external link
- Fixed
2.0.0(202?-??-??)- Refactored names
- Refactored scopes
- Refactored promises
- Refactored errors
- Refactored indents
- Renamed
getLocationtogetLocationById - Reverse subscribe methods
post&errorparameters - Improved unit tests coverage - Added JSDoc - Added links to partial post, hashtag & location - Fixed post author link