forked from bbc/wraith
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snap.js
39 lines (30 loc) · 1.12 KB
/
snap.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
var system = require('system');
var page = require('webpage').create();
var fs = require('fs');
if (system.args.length === 3) {
console.log('Usage: snap.js <some URL> <view port width> <target image name>');
phantom.exit();
}
var url = system.args[1];
var image_name = system.args[3];
var view_port_width = system.args[2];
page.viewportSize = { width: view_port_width, height: 5000};
page.settings = { loadImages: true, javascriptEnabled: true };
//if you want to use additional phantomjs commands, place them here
page.settings.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.17',
//You can place custom headers here, example below.
// page.customHeaders = {
// 'X-Candy-OVERRIDE': 'https://api.live.bbc.co.uk/'
// };
page.open(url, function(status) {
if (status === 'success') {
window.setTimeout(function() {
console.log('Snapping ' + url + ' at width ' + view_port_width);
page.render(image_name);
phantom.exit();
}, 3000);
} else {
console.log('Error with page ' + url);
phantom.exit();
}
});