-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (33 loc) · 1.02 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
const puppeteer = require('puppeteer')
const CronJob = require('cron').CronJob
const dotenv = require('dotenv')
dotenv.config()
async function run() {
const browser = await puppeteer.launch()
const page = await browser.newPage()
// const navigationPromise = page.waitForNavigation({waitUntil: ['networkidle2'] });
await page.setViewport({
width: 1920,
height: 1080,
deviceScaleFactor: 1,
})
await page.goto('https://stackoverflow.com/users/login')
await page.waitForSelector('input#email')
await page.type('input#email', process.env.EMAIL)
await page.waitForSelector('input#password')
await page.type('input#password', process.env.PASS)
await Promise.all([
page.keyboard.press('Enter'),
page.waitForNavigation({ waitUntil: 'networkidle0', timeout: 10000 }),
])
await page.screenshot({ path: `img/${new Date()}.png` })
await browser.close()
}
// run()
const task = new CronJob({
cronTime: '* * 0 * * *',
onTick: run,
start: false,
timeZone: 'Europe/London',
})
task.start()