-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinterest.js
133 lines (121 loc) · 3.92 KB
/
pinterest.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
122
123
124
125
126
127
128
129
130
131
132
133
// Automation Project on Pinterest for maintaining a healthy body
let puppeteer = require("puppeteer");
let credFile = process.argv[2];
let fs = require("fs");
(async function () {
try {
let data = await fs.promises.readFile(credFile);
let {
url,
user,
pwd,
nPost,
searchInput,
searchInput2
} = JSON.parse(data);
//for chrome
// const browser = await puppeteer.launch({
// executablePath: "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
// headless: false,
// defaultViewport:null,
// args: ["--start-maximized", "--disable-notifications",]
// });
//launch puppeteer
let browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
args: ["--start-maximized", "--disable-notifications"]
});
let pages = await browser.pages();
let page = pages[0];
await page.goto(url, {
waitUntil: "load",
timeout: 0
});
await page.waitForSelector("#email");
await page.type("#email", user, {
delay: 150
});
await page.type("#password", pwd, {
delay: 150
});
await Promise.all([page.click(".red.SignupButton.active"), page.waitForNavigation({
waitUntil: "load"
})]);
// await page.waitForNavigation({waitUntil:"load"});
await page.waitForSelector('input[name="searchBoxInput"]');
await page.type('input[name="searchBoxInput"]', searchInput, {
delay: 150
});
await page.keyboard.press('Enter');
let idx = 0;
do {
await page.waitForSelector(".vbI.XiG");
console.log("Inside the loop");
await page.evaluate(() => {
window.scrollBy(0, 1000);
});
function delay(time) {
return new Promise(function (resolve) {
setTimeout(resolve, time)
});
}
await delay(4000);
let elements = await page.$$(".Yl-.MIw.Hb7");
console.log("Elements are: " + elements);
let pic = elements[idx];
await Promise.all([pic.click({
delay: 150
}), page.waitForNavigation({
waitUntil: "load"
})]);
await page.waitForSelector(".PinBetterSave__Button.PinBetterSave__Button--lego");
await page.click(".PinBetterSave__Button.PinBetterSave__Button--lego");
console.log(idx + 1 + "post(s) saved");
idx++;
// PinBetterSave__Button PinBetterSave__Button--lego
// SaveButton SaveButton--enabled
} while (idx < nPost)
console.log("Posts Saved!!");
//-------------------------
await page.waitForSelector('input[name="searchBoxInput"]');
await page.type('input[name="searchBoxInput"]', searchInput2, {
delay: 150
});
await page.keyboard.press('Enter');
let idxx = 0;
do {
await page.waitForSelector(".vbI.XiG");
console.log("Inside the loop");
await page.evaluate(() => {
window.scrollBy(0, 1000);
});
function delay(time) {
return new Promise(function (resolve) {
setTimeout(resolve, time)
});
}
await delay(4000);
let elements = await page.$$(".Yl-.MIw.Hb7");
console.log("Elements are: " + elements);
let pic = elements[idxx];
await Promise.all([pic.click({
delay: 150
}), page.waitForNavigation({
waitUntil: "load"
})]);
await page.waitForSelector(".PinBetterSave__Button.PinBetterSave__Button--lego");
await page.click(".PinBetterSave__Button.PinBetterSave__Button--lego");
console.log(idxx + 1 + "post(s) saved");
idxx++;
// PinBetterSave__Button PinBetterSave__Button--lego
// SaveButton SaveButton--enabled
} while (idxx < nPost)
console.log("Posts Saved!!");
//----------------------------
// await browser.close();
} catch (err) {
console.log("Error is: " + err);
}
})
()