Answer the question
In order to leave comments, you need to log in
Is PhantomJS a Bad Choice?
Started to deal with PhantomJS. I am running a simple script:
var system = require('system');
var os = system.os;
var args = system.args;
var scriptName = args[0];
var name = args[1];
var url = args[2];
var page = require('webpage').create();
// ERROR HANDLING
var webPage = require('webpage');
var page = webPage.create();
page.onError = function(msg, trace) {
var msgStack = ['ERROR: ' + msg];
if (trace && trace.length) {
msgStack.push('TRACE:');
trace.forEach(function(t) {
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
});
}
console.error(msgStack.join('\n'));
};
// END
if(args.length === 2) {
throw new Error('Name as system argument missing.');
}
console.log(
'Hey ' + name + '.\n' +
'You PC is ' + os.architecture + ' ' + os.name + os.version + '.\n' +
'Executed: ' + scriptName + '.\n' +
'Opening ' + url + '...'
);
page.open(url, function(status) {
console.log('Status: ' + status);
// Do other things here...
page.viewportSize = {
width: 1200,
height: 1000
};
page.render('image1200.png');
console.log('Rendered image: ' + url + '(1200px)');
page.viewportSize = {
width: 800,
height: 1000
};
page.render('image800.png');
console.log('Rendered image: ' + url + '(800px)');
page.viewportSize = {
width: 500,
height: 1000
};
page.render('image500.png');
console.log('Rendered image: ' + url + '(500px)');
// EXIT
phantom.exit();
});
Answer the question
In order to leave comments, you need to log in
PhantonJS is not perfect, of course, but as a scripter it works quite well for itself. 3 minutes is certainly overkill, the problem is clearly somewhere in the written JS code. I made 3 screenshots ( 1200*1000 , 800*1000 , 500*1000 ) of the given page, it turned out somewhere in ~ 7 seconds for each (while PhantomJS is on a remote machine and goes through a proxy itself). The page itself, yes, swam a little. But it is possible, because it is based on an old webkit. If you need screenshots from the latest versions of browsers, then of course it may not be suitable.
maybe because of this?
page.viewportSize = {
width: 1200,
height: 1000
};
page.render('image1200.png');
console.log('Rendered image: ' + url + '(1200px)');
page.viewportSize = {
width: 800,
height: 1000
};
page.render('image800.png');
console.log('Rendered image: ' + url + '(800px)');
page.viewportSize = {
width: 500,
height: 1000
};
page.render('image500.png');
console.log('Rendered image: ' + url + '(500px)');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question