-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (49 loc) · 1.83 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
const puppeteer=require('puppeteer');
let {username,password}=require('./config');
let search_term=process.argv.slice(2)?process.argv.slice(2)[0]:null;
if(!search_term){
console.log("Please provide search term");
return;
}
let browser,tab;
async function login(username,password){
await tab.waitForSelector("input[name='username']");
await tab.type("input[name='username']",username,{delay:100});
await tab.type("input[name='password']",password,{delay:100});
await tab.click("button[type='submit']");
await tab.waitForSelector("input[placeholder='Search']");
}
async function search(query){
await tab.type("input[placeholder='Search']",query);
await tab.waitForSelector('.-qQT3');
await tab.click('.-qQT3');
await tab.waitForSelector('article a'); //waiting to go to first search
await tab.click('article a'); //clicking on the first post
await tab.waitForSelector("article[role='presentation']") // waiting to open first post
}
async function likePost(){
let elem=await tab.$("section svg[aria-label='Like']")
if(elem!=null){ // checking if it is liked previously then dont do this
await tab.waitForSelector("section svg[aria-label='Like']");
await tab.click("section svg[aria-label='Like']");
}
}
async function LikeAllPosts(){
for(let i=0;i<10;i++){
await tab.waitForTimeout(3000);
await likePost();
await tab.waitForTimeout(2000);
await tab.click(".coreSpriteRightPaginationArrow");
}
}
async function main(){
browser=await puppeteer.launch({headless:false,defaultViewport:null});
let page=await browser.pages();
tab=page[0];
await tab.goto('https://www.instagram.com/');
await login(username,password);
await search(search_term)
await LikeAllPosts();
console.log("all post liked");
}
main();