user-instagram
Advanced tools
Comparing version 1.0.4 to 1.1.0
18
index.js
@@ -1,14 +0,6 @@ | ||
const request = require("request-promise") | ||
const { getData } = require("./src/scrape") | ||
function scrape(url) { | ||
return new Promise((resolve, reject) => { | ||
request(url).then(data => { | ||
resolve(getData(data)) | ||
}).catch(e => { | ||
reject(e) | ||
}) | ||
}) | ||
} | ||
const handle = require("./src/handle"); | ||
module.exports = scrape | ||
/** | ||
* @param profileInfo { String } | ||
*/ | ||
module.exports = handle; |
{ | ||
"name": "user-instagram", | ||
"version": "1.0.4", | ||
"description": "Get user data and feed by scraping Instagram's user page. No need for O-Auth or API.", | ||
"version": "1.1.0", | ||
"description": "Get user data and feed content by scraping Instagram's user page. No OAuth needed.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node test/test.js" | ||
}, | ||
@@ -24,6 +24,5 @@ "keywords": [ | ||
"dependencies": { | ||
"cheerio": "^1.0.0-rc.3", | ||
"request": "^2.88.0", | ||
"request-promise": "^4.2.4" | ||
"axios": "^0.19.2", | ||
"cheerio": "^1.0.0-rc.3" | ||
} | ||
} |
# Node-Instagram | ||
[![NPM](https://nodei.co/npm/user-instagram.png)](https://nodei.co/npm/user-instagram) | ||
This module allow you to get user data from instagram link. | ||
<b>Example:</b> | ||
## Introduction | ||
The aim of this module is to provide an easy way to retrieve a user's Instagram data. | ||
This module is available on NPM. | ||
``` | ||
npm install user-instagram | ||
``` | ||
## Usage | ||
I tried to make this module user-friendly as much as I could. Just provide a username or a profile link. | ||
> edouard_courty | ||
> https://www.instagram.com/edouard_courty | ||
```js | ||
const instagram = require("user-instagram") | ||
const getInstaProfile = require("user-instagram"); | ||
instagram("https://www.instagram.com/edouard_courty") | ||
.then(data => { | ||
console.log(`Full name is: ${data.fullName}`) | ||
}) | ||
.catch(e => { | ||
// Error will trigger if the account link provided is false. | ||
console.error(data) | ||
}) | ||
getInstaProfile("edouard_courty") | ||
.then(userData => { | ||
console.log(userData.user) | ||
}) | ||
.catch(console.error); | ||
``` | ||
This module only uses ES6 Promises. | ||
By the future, i'll update this module to add methods. | ||
## Data Structure | ||
[Creator's website](https://edouard-courty.fr) | ||
The output will look like the following: | ||
```json | ||
{ | ||
profileLink: 'https://www.instagram.com/edouard_courty', | ||
subscriberCount: 444, | ||
subscribtions: 362, | ||
postCount: 27, | ||
username: 'edouard_courty', | ||
isPrivate: false, | ||
isVerified: false, | ||
fullName: 'Edouard Courty', | ||
bio: "<userBio", | ||
id: '<userId>', | ||
avatar: <avatarThumbnailLink>, | ||
avatarHD: <HDAvatarLink>, | ||
posts: [] | ||
} | ||
``` | ||
This module uses ES6 Promises. | ||
© 2020 - Edouard Courty |
@@ -1,53 +0,56 @@ | ||
const cheerio = require("cheerio") | ||
const cheerio = require("cheerio"); | ||
function getData(body) { | ||
var $ = cheerio.load(body) | ||
var scripts = $("script[type='text/javascript']") | ||
var sharedData = JSON.parse( | ||
scripts[3].children[0].data | ||
.replace("window._sharedData = ", "") | ||
.replace("};", "}") | ||
) | ||
var graphql = sharedData.entry_data.ProfilePage[0].graphql.user | ||
return { | ||
"profileLink": "https://www.instagram.com/".concat(graphql.username), | ||
"subscriberCount": graphql.edge_followed_by.count, | ||
"subscribtions": graphql.edge_follow.count, | ||
"postCount": graphql.edge_owner_to_timeline_media.count, | ||
"username": graphql.username, | ||
"isPrivate": graphql.is_private, | ||
"isVerified": graphql.is_verified, | ||
"fullName": graphql.full_name, | ||
"bio": graphql.biography, | ||
"id": graphql.id, | ||
"postCount": graphql.edge_owner_to_timeline_media.count, | ||
"avatar": graphql.profile_pic_url, | ||
"avatarHD": graphql.profile_pic_url_hd, | ||
"posts": graphql.edge_owner_to_timeline_media.edges.map(edge => { | ||
return { | ||
"id": edge.node.id, | ||
"captionText": edge.node.edge_media_to_caption.edges.length === 0 ? null : edge.node.edge_media_to_caption.edges[0].node.text, | ||
"shortcode": edge.node.shortcode, | ||
"link": `https://www.instagram.com/p/${edge.node.shortcode}`, | ||
"commentsCount": edge.node.edge_media_to_comment.count, | ||
"timestamp": edge.node.taken_at_timestamp, | ||
"likes": edge.node.edge_liked_by.count, | ||
"location": edge.node.location || null, | ||
"picture": { | ||
"url": edge.node.thumbnail_src, | ||
"thumbnail_150": edge.node.thumbnail_resources[0].src, | ||
"thumbnail_240": edge.node.thumbnail_resources[1].src, | ||
"thumbnail_320": edge.node.thumbnail_resources[2].src, | ||
"thumbnail_480": edge.node.thumbnail_resources[3].src, | ||
"thumbnail_640": edge.node.thumbnail_resources[4].src | ||
}, | ||
"isVideo": edge.node.is_video | ||
} | ||
module.exports = body => { | ||
return new Promise((resolve, reject) => { | ||
let $ = cheerio.load(body); | ||
let scripts = $("script[type='text/javascript']"), graphql; | ||
try { | ||
graphql = JSON.parse( | ||
scripts[3].children[0].data | ||
.replace("window._sharedData = ", "") | ||
.replace("};", "}") | ||
).entry_data.ProfilePage[0].graphql.user; | ||
} catch (e) { | ||
return reject(e) | ||
} | ||
return resolve({ | ||
"profileLink": "https://www.instagram.com/".concat(graphql.username), | ||
"subscriberCount": graphql.edge_followed_by.count, | ||
"subscribtions": graphql.edge_follow.count, | ||
"postCount": graphql.edge_owner_to_timeline_media.count, | ||
"username": graphql.username, | ||
"isPrivate": graphql.is_private, | ||
"isVerified": graphql.is_verified, | ||
"fullName": graphql.full_name, | ||
"bio": graphql.biography, | ||
"id": graphql.id, | ||
"avatar": graphql.profile_pic_url, | ||
"avatarHD": graphql.profile_pic_url_hd, | ||
"posts": graphql.edge_owner_to_timeline_media.edges.map(edge => { | ||
return { | ||
"id": edge.node.id, | ||
"captionText": edge.node.edge_media_to_caption.edges.length === 0 | ||
? null | ||
: edge.node.edge_media_to_caption.edges[0].node.text, | ||
"shortcode": edge.node.shortcode, | ||
"link": `https://www.instagram.com/p/${edge.node.shortcode}`, | ||
"commentsCount": edge.node.edge_media_to_comment.count, | ||
"timestamp": edge.node.taken_at_timestamp, | ||
"likes": edge.node.edge_liked_by.count, | ||
"location": edge.node.location || null, | ||
"picture": { | ||
"url": edge.node.thumbnail_src, | ||
"thumbnail_150": edge.node.thumbnail_resources[0].src, | ||
"thumbnail_240": edge.node.thumbnail_resources[1].src, | ||
"thumbnail_320": edge.node.thumbnail_resources[2].src, | ||
"thumbnail_480": edge.node.thumbnail_resources[3].src, | ||
"thumbnail_640": edge.node.thumbnail_resources[4].src | ||
}, | ||
"isVideo": edge.node.is_video | ||
} | ||
}) | ||
}) | ||
} | ||
} | ||
module.exports = { getData } | ||
}) | ||
}; |
@@ -1,10 +0,5 @@ | ||
const scrape = require("../index") | ||
const scrape = require("../index"); | ||
scrape("https://www.instagram.com/edouard_courty").then(result => { | ||
console.log(result) | ||
}).catch(e => { | ||
console.error(e) | ||
}) | ||
// This will log an object containing user data, and an array containing the 12 first posts of the account. | ||
// I'll update this module and git repository when i'll have found how to get all the posts | ||
scrape("edouard_courty") | ||
.then(console.log) | ||
.catch(console.error); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
4435
2
6
74
1
50
+ Addedaxios@^0.19.2
+ Addedaxios@0.19.2(transitive)
+ Addedfollow-redirects@1.5.10(transitive)
- Removedrequest@^2.88.0
- Removedrequest-promise@^4.2.4
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbluebird@3.7.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.13.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrequest-promise@4.2.6(transitive)
- Removedrequest-promise-core@1.1.4(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstealthy-require@1.1.1(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)