-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
121 lines (73 loc) · 3.7 KB
/
index.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const myUsername = ""; // Place usename here
const myPassword = ""; // Place password here
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch(); //{headless: false}
const page = await browser.newPage();
await page.goto('https://www.instagram.com/accounts/login/'); //, {waitUntil: 'networkidle2'}
//login to instagram
await page.waitForSelector('input[name="username"]');
await page.type('input[name="username"]', myUsername);
await page.type('input[name="password"]', myPassword);
await page.click('button[type="submit"]');
//once login is complete go to profile
await page.waitForNavigation();
await page.goto('https://www.instagram.com/' + myUsername, {waitUntil: 'networkidle2'});
// Get number of followers and following
const followersCount = await page.evaluate(() => document.querySelector('.k9GMp li a span').textContent );
console.log("followersCount: " + followersCount);
const followingCount = await page.evaluate(() => document.querySelector('.k9GMp').lastChild.textContent.replace(/\D/g,''));
console.log("followingCount: " + followingCount);
//await page.waitFor(1000);
// Open followers List
await page.click('a[href="/' + myUsername +'/followers/"]');
//await page.waitFor(1000);
// Scroll until you got the whole list of followers into view
let followersList = await page.evaluate(() => document.querySelectorAll(".PZuss li").length);
while(followersList < followersCount){
await page.waitForSelector('.PZuss');
await page.evaluate(() => document.querySelector(".PZuss").lastChild.scrollIntoView() );
await page.waitFor(300);
followersList = await page.evaluate(() => document.querySelectorAll(".PZuss li").length);
//console.log("followersList: " + followersList);
}
const followers = {
name: await page.evaluate(() => Array.from(document.querySelectorAll('.PZuss li .FPmhX'), element => element.textContent)),
img: await page.evaluate(() => Array.from(document.querySelectorAll('.PZuss li ._6q-tv'), element => element.src))
}
// Close followers window
await page.click('div > button > div > svg');
await page.waitFor(1000);
// Open following List
await page.click('a[href="/' + myUsername +'/following/"]');
//await page.waitFor(2000);
let followingList = await page.evaluate(() => document.querySelectorAll(".PZuss li").length);
while(followingList < followingCount){
await page.waitForSelector('.PZuss');
await page.evaluate(() => document.querySelector(".PZuss").lastChild.scrollIntoView() );
await page.waitFor(300);
followingList = await page.evaluate(() => document.querySelectorAll(".PZuss li").length);
//console.log("followingList: " + followingList);
}
const following = {
name: await page.evaluate(() => Array.from(document.querySelectorAll('.PZuss li .FPmhX'), element => element.textContent)),
img: await page.evaluate(() => Array.from(document.querySelectorAll('.PZuss li ._6q-tv'), element => element.src))
}
// Make the 3 lists ( friends , fans , notFollowBack )
let friends = [];
let fans = [];
let notFollowBack = [];
friends = followers.name.filter(function(e) {
return following.name.indexOf(e) > -1;
});
console.log("FRIENDS: " + friends.length);
fans = followers.name.filter(function(e) {
return following.name.indexOf(e) == -1;
});
console.log("FANS: " + fans.length);
notFollowBack = following.name.filter(function(e) {
return followers.name.indexOf(e) == -1;
});
console.log("notFollowBack: " + notFollowBack.length);
await browser.close();
})();