forked from rjrodriguezalvarez97/auto-comments-instagram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (70 loc) · 1.95 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
const { Builder, By, Key, util } = require("selenium-webdriver");
const {
INSTAGRAM_POST,
USERS,
INSTAGRAM_USER,
INSTAGRAM_PASSWORD,
} = require("./config.js");
require("chromedriver");
async function run() {
let driver = await new Builder().forBrowser("chrome").build();
await driver.get("https://instagram.com");
console.log("Finding Cookies Popup");
await driver
.findElement(By.xpath("/html/body/div[4]/div/div/button[1]"))
.click();
console.log("Log in");
await driver
.findElement(
By.xpath(
"/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input"
)
)
.sendKeys(INSTAGRAM_USER);
await driver
.findElement(
By.xpath(
"/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[2]/div/label/input"
)
)
.sendKeys(INSTAGRAM_PASSWORD);
await driver
.findElement(
By.xpath(
"/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[3]/button"
)
)
.click();
console.log("Logged in successfully");
await driver.sleep(5000);
console.log("Going to post");
await driver.get(INSTAGRAM_POST);
await driver.sleep(5000);
for (let i = 0; i < USERS.length; i++) {
if (i > 0 && i % 10 == 0) {
console.log("Waiting 5 minutes before commenting");
await driver.sleep(300000);
console.log("Continue...");
}
const user = "@" + USERS[i];
console.log(`Mentioning ${user}`);
await driver
.findElement(
By.xpath(
"/html/body/div[1]/section/main/div/div[1]/article/div[3]/section[1]/span[2]/button"
)
)
.click();
const action = driver.actions();
await action.sendKeys(user).perform();
await driver
.findElement(
By.xpath(
"/html/body/div[1]/section/main/div/div[1]/article/div[3]/section[3]/div/form/button[2]"
)
)
.click();
await driver.sleep(15000);
}
}
run();