-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrapedata3.js
102 lines (43 loc) · 2 KB
/
scrapedata3.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
const puppeteer = require('puppeteer');
const fs = require('fs');
require('dotenv').config();
let scrapeData = async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.setViewport({ width: 1366, height: 768 });
await page.goto('https://my.wonderbill.com/login', {waitUntil: 'networkidle2'})
.catch(e => console.error(e)); //The snippet throws an error that you can catch with .catch() promise method.
await page.click('#_evidon-accept-button');
//Enter username and password
await page.type('input[type=email]', process.env.email)
await page.type('input[type="password"]', process.env.password)
//login button
await page.click('#page-wrapper > div > div > div > section > form > button')
await page.waitFor(1000);
await page.waitForSelector('.\_2bmqM > section > .\_1aUg5 > .\_1mm64:nth-child(3) > .\_3E9gF')
await page.click('.\_2bmqM > section > .\_1aUg5 > .\_1mm64:nth-child(3) > .\_3E9gF')
await page.waitForSelector('div > div > .\_2RfCm > .TiUAv > .\_2y6-o')
await page.click('div > div > .\_2RfCm > .TiUAv > .\_2y6-o')
await page.waitFor(5000);
//Generate image and pdf
await page.screenshot({ path: './image.jpg', fullPage: true });
// await page.pdf({ path: "./page.pdf", format: "A4", printBackground: true });
page.on('requestfailed', err => console.error('REQUEST_FAILED:\n' + util.inspect(err)))
const accounts = await page.evaluate(() => {
let accountName = document.querySelector('#accountName').value;
let amountPaidEachMonth = document.querySelector('#amount').value;
let datePaid = document.querySelector('#datePaid').value;
return [{
accountName,
amountPaidEachMonth,
datePaid
}]
})
return accounts
}
scrapeData().then((value) => {
console.log(value);
fs.appendFile('accounts.json', JSON.stringify(value), function (err) {
if (err) throw err;
});
});