-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
90 lines (69 loc) · 2.31 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
const puppeteer = require("puppeteer");
const credentials = require("./credentials");
const Sheet = require("./sheet");
(async () => {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto("https://instagram.com");
await page.waitForSelector("input");
const usernameAndPasswordInputBoxes = await page.$$("input");
const usernameInputBox = usernameAndPasswordInputBoxes[0];
const passwordInputBox = usernameAndPasswordInputBoxes[1];
await usernameInputBox.type(credentials.USERNAME);
await passwordInputBox.type(credentials.PASSWORD);
const loginButton = (await page.$$("button"))[1];
await loginButton.click();
await page.waitForNavigation();
const sheet = new Sheet();
await sheet.load();
const allUsernames = (await sheet.getRows(0)).map((row) => row.username);
const profiles = [];
for (let i = 0; i < allUsernames.length; i++) {
let USERNAME = allUsernames[i];
await page.goto(`https://instagram.com/${USERNAME}`);
await page.waitForSelector("img");
const profilePicSrc = await page
.$eval("img", (element) => element.getAttribute("src"))
.catch((err) => false);
const stats = await page
.$$eval("header li", (elements) =>
elements.map((element) => element.textContent)
)
.catch((err) => false);
const fullName = await page
.$eval("._aa_c span", (element) => element.textContent)
.catch((err) => false);
const bio = await page
.$eval(
"._aa_c ._aacl._aacp._aacu._aacx._aad6._aade",
(element) => element.textContent
)
.catch((err) => false);
const profileLink = await page
.$eval(
"._aacl._aacp._aacw._aacz._aada._aade",
(element) => element.textContent
)
.catch((err) => false);
const profile = {
profilePicSrc,
fullName,
bio,
profileLink,
username: USERNAME,
};
for (let stat of stats) {
const [count, name] = stat.split(" ");
profile[name] = count;
}
profiles.push(profile);
}
const prevProfiles = await sheet.getRows(1);
for (let prevProfile of prevProfiles) {
if (allUsernames.includes(prevProfile.username)) {
await prevProfile.delete();
}
}
await sheet.addRows(profiles, 1);
await browser.close();
})();