-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (44 loc) · 1.6 KB
/
index.js
File metadata and controls
54 lines (44 loc) · 1.6 KB
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
const puppeteer = require('puppeteer');
require('dotenv').config()
const LOGIN = process.env.URL_LOGIN;
const TRACKING = (day) => process.env.URL_TRACK;
const day_id = `20201007`;
function getFrame(page, name) {
let frame = page.mainFrame();
for (let child of frame.childFrames()) {
if (name === child.name()) {
return child;
}
}
}
(async () => {
try {
const browser = await puppeteer.launch({
devtools: false,
headless: true
});
const page = (await browser.pages())[0];
await page.goto(LOGIN);
await page.waitForSelector('frameset')
let frame = getFrame(page, 'Hauptframe')
await frame.type('#InpEmpId', process.env.TIMEMAG_USER);
await frame.type('#InpEmpPwd', process.env.TIMEMAG_PASS);
await frame.click('button');
await page.waitForSelector('frame[name="Main"]')
frame = getFrame(page, 'Main')
await frame.waitForSelector('#butterfly');
await page.goto(TRACKING(day_id), {waitUntil: 'networkidle0'});
await page.waitForSelector('td.iflxCorrectionTab input');
const array = await page.evaluate(() => {
return [...document.querySelectorAll('td.iflxCorrectionTab input')]
.map(x => x.value)
.filter(e => e !== '' && e !== 'false')
})
const result = array.filter((e, i) => i%3===0);
console.log(result.length % 2 !== 0) // true logged back in, false forgot it...
await browser.close();
} catch (e) {
console.error(e);
process.exit = 1;
}
})();