-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-bot.js
100 lines (73 loc) · 4.15 KB
/
post-bot.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
const puppeteer = require('puppeteer');
const fs = require('fs');
const iPhone = puppeteer.devices['iPhone X'];
// const iPhonex = devices['iPhone X'];
(function instaBot() {
(async () => {
const browser = await puppeteer.launch({"headless": false,
executablePath:'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
defaultViewport: null, args: ['--start-maximized']});
const page = await browser.newPage();
await page.emulate(iPhone);
await page.goto('https://www.instagram.com/');
//Wait for cookies to load
await page.waitForSelector( 'body > div.RnEpo.Yx5HN > div > div > div > div.mt3GC > button.aOOlW.bIiDR', {visible: true} );
//Accept cookies
await page.click( 'body > div.RnEpo.Yx5HN > div > div > div > div.mt3GC > button.aOOlW.bIiDR');
//wait for login button to load
await page.waitForSelector('#react-root > section > main > article > div > div > div > div:nth-child(2) > button');
//click on login button
await page.click( '#react-root > section > main > article > div > div > div > div:nth-child(2) > button');
//wait for username
await page.waitForSelector('input[name="username"]')
//enter username and password
await page.type('input[name="username"]', 'example username');
await page.type('input[name="password"]', 'example password');
//click submit button
await page.click('button[type="submit"]');
//wait for don't save login info
await page.waitForSelector('#react-root > section > main > div > div > div > button');
//click on don't save login info
await page.click('#react-root > section > main > div > div > div > button');
//wait for add to home
// await page.waitForSelector('body > div.RnEpo.Yx5HN > div > div > div > div.mt3GC > button.aOOlW.HoLwm');
// //click on don't add
// await page.click('body > div.RnEpo.Yx5HN > div > div > div > div.mt3GC > button.aOOlW.HoLwm');
//dont turn on notifications
await page.waitForSelector('body > div.RnEpo.Yx5HN > div > div > div > div.mt3GC > button.aOOlW.HoLwm');
//click on dont turn on notifs
await page.click('body > div.RnEpo.Yx5HN > div > div > div > div.mt3GC > button.aOOlW.HoLwm');
//Creates an Array of the names of the files in the folder
var files = fs.readdirSync('./images/')
let chosenFile = files[Math.floor(Math.random() * files.length)]
//Chooses file
const [fileChooser] = await Promise.all([
page.waitForFileChooser(),
page.click('#react-root > section > nav.NXc7H.f11OC > div > div > div.KGiwt > div > div > div.q02Nz._0TPg > svg > path:nth-child(1)'), // some button that triggers file selection
]);
//Closes the file dialog window
await fileChooser.accept([`./images/${chosenFile}`]);
await page.waitForTimeout(5000);
//Remove File From Directory so it isn't selected again
const path = `./images/${chosenFile}`;
try {
//remove file
fs.unlinkSync(path)
} catch(err){
console.error(err)
}
//Next on image upload
await page.waitForSelector('#react-root > section > div.Scmby > header > div > div.mXkkY.KDuQp > button');
await page.click('#react-root > section > div.Scmby > header > div > div.mXkkY.KDuQp > button');
//Add Tags on image
await page.waitForSelector('#react-root > section > div.A9bvI > section.IpSxo > div.NfvXc > textarea');
await page.type('#react-root > section > div.A9bvI > section.IpSxo > div.NfvXc > textarea', '#mentalhealth #mentalhealthawareness #selfcare #selflove #love #anxiety #motivation #depression #health #mentalhealthmatters #life #mindfulness #loveyourself #wellness #inspiration #fitness #healing #happiness #positivity #positivevibes #quotes #mindset #therapy #covid #instagood #happy #meditation #mentalillness #yourself #bhfyp');
await page.waitForTimeout(5000);
//Click on Share button
await page.waitForSelector('#react-root > section > div.Scmby > header > div > div.mXkkY.KDuQp > button');
await page.click('#react-root > section > div.Scmby > header > div > div.mXkkY.KDuQp > button');
await page.waitForTimeout(10000);
await browser.close();
})();
// setTimeout(instaBot, 3630000);
})();