-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-instagram.js
66 lines (55 loc) · 1.47 KB
/
index-instagram.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const request = require('request-promise');
const cheerio = require('cheerio');
(async () => {
const USERNAME = 'pablostanley';
const BASE_URL = `https://instagram.com/${USERNAME}`;
let response = await request(BASE_URL);
let $ = cheerio.load(response);
let script = $('script[type="text/javascript"]').eq(3).html();
let scriptRegex = /window._sharedData = (.+);/g.exec(script);
let {
entry_data: {
ProfilePage: {
[0]: {
graphql: { user },
},
},
},
} = JSON.parse(scriptRegex[1]);
let {
entry_data: {
ProfilePage: {
[0]: {
graphql: {
user: {
edge_owner_to_timeline_media: { edges },
},
},
},
},
},
} = JSON.parse(scriptRegex[1]);
let posts = [];
for (let edge of edges) {
let { node } = edge;
posts.push({
id: node.id,
shortcode: node.shortcode,
timestamp: node.taken_at_timestamp,
likes: node.edge_liked_by.count,
comments: node.edge_media_to_comment.count,
video_views: node.video_view_count,
// caption: node.edge_media_to_caption.edges[0].node.text,
image_url: node.display_url,
});
}
let instagram_data = {
followers: user.edge_followed_by.count,
following: user.edge_follow.count,
uploads: user.edge_owner_to_timeline_media.count,
full_name: user.full_name,
picture_url: user.profile_pic_url_hd,
posts: posts,
};
debugger;
})();