-
Notifications
You must be signed in to change notification settings - Fork 0
/
server4you.js
79 lines (71 loc) · 2.45 KB
/
server4you.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
#!/usr/bin/env node
const puppeteer = require('puppeteer');
const fs = require('fs');
const { program } = require('commander');
const fetcher = function(parameters) {
(async () => {
const browser = await puppeteer.launch({ headless: true }); // For Debugging
const page = await browser.newPage();
page.on('console', (msg) => console.log('PAGE LOG:', msg.text()));
await page.goto('https://my.server4you.de/de/Generic/Auth/Index/login');
await page.waitForSelector('input[name=username]');
await page.evaluate((arg) => $('input[name=username]').val(arg),parameters.username);
await page.evaluate((arg) => $('input[name=password]').val(arg),parameters.password);
await page.evaluate(() => $('input[value=Einloggen]').click());
await page.waitForSelector('.submenu');
await page.goto('https://my.server4you.de/de/Customer/Invoice?');
await page.waitForSelector('#openInvoices');
await page._client.send('Page.setDownloadBehavior', {
behavior: 'allow',
downloadPath: parameters.path
});
{
}
const invoices = await page.evaluate(() => {
let links = $('a');
let downloads = [];
for(let i=0;i<links.length;i++) {
if(links[i].href.startsWith('https://my.server4you.de/de/Customer/Invoice/Index/download/id/')) {
downloads.push(links[i].href);
}
}
return downloads;
});
for(let i=0;i<invoices.length;i++) {
await page.evaluate((url) => {
const link = document.createElement("a");
link.setAttribute("href", url);
document.body.appendChild(link);
return link.click();
},invoices[i]);
}
await browser.close();
})();
}
program
.option('-u --username [account]','Username of service')
.option('-p --password [password]','Password of service')
.option('-d --path [folder]','Directory to store retrieved PDF invoices to (relative to runtime)')
program.parse();
const options = program.opts();
const args = program.args;
if(options.username == null) {
console.log('required parameter -u [account]');
process.exit(1);
}
if(options.password == null) {
console.log('required parameter -p [password]');
process.exit(1);
}
if(options.path == null) {
console.log('required parameter -d [path]');
process.exit(1);
}
fetcher(options);
/*
fetcher({
username:'epiktet',
password:'w9xHccrH2hvO',
path:'.'
});
*/