-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender-page.js
More file actions
48 lines (35 loc) · 1.22 KB
/
render-page.js
File metadata and controls
48 lines (35 loc) · 1.22 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
var page = require('webpage').create(), config = require('./config.json');
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
page.viewportSize = {
width: config.width,
height: config.height
};
function login_callback (status) {
if (status != "success") {
console.log("Failure loading login page");
return
}
page.onLoadFinished = post_login_callback;
page.evaluate(function () {
document.querySelector(config.userfield).value=config.username;
document.querySelector(config.passfield).value=config.password;
document.querySelector(config.formSel).submit();
});
}
function post_login_callback (status) {
if (status != "success") {
console.log("Failure logging in");
return
}
page.onLoadFinished = render_page;
page.open(config.redirectURI);
}
function render_page (status) {
window.setTimeout(function () {
console.log("Rendering to " + config.folder + " folder...");
page.render(config.folder + "/" + config.outputFile);
phantom.exit();
}, config.timeout);
}
page.onLoadFinished = login_callback;
page.open(config.initialPage);