-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
50 lines (42 loc) · 1.46 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
const puppeteer = require('puppeteer');
var cron = require('node-cron');
const CREDS = require('./creds');
function delay(time) {
return new Promise(function (resolve) {
setTimeout(resolve, time)
});
}
const start = async () => {
const browser = await puppeteer.launch({
headless: true,
});
const page = await browser.newPage();
await page.setViewport({
width: 1800,
height: 768
});
await page.goto('https://my.yad2.co.il/login.php');
await page.waitForSelector('#userName');
await page.$eval('#userName', (el, creds) => el.value = creds.username, CREDS);
await page.waitForSelector('#password');
await page.$eval('#password', (el, creds) => el.value = creds.password, CREDS);
await page.click('#submitLogonForm');
await page.waitForSelector('.content-wrapper.active');
await page.goto(CREDS.link);
await page.waitForSelector('#sLightbox_container > div > div.close_btn');
await page.click('#sLightbox_container > div > div.close_btn');
await delay(2000);
await page.waitForSelector('#bounceRatingOrderBtn');
await page.focus('#bounceRatingOrderBtn');
await page.click('#bounceRatingOrderBtn');
await page.waitForSelector('.viewCommandGreenBtn');
await delay(2000);
await page.screenshot({
path: (new Date().toLocaleString().split('/').join('-').split(':').join('-').replace(', ', '-').replace(' PM', '').replace(' AM') + '.png')
});
await browser.close();
}
start();
cron.schedule('0 */4 * * *', () => {
start()
});