Javascript PhantomJS无法从html源文件生成JPG
我试图从html源代码生成JPG图像,但脚本甚至生成了0KB的JPG文件 状态=成功 此html源没有错误日志 同样的脚本也适用于其他html源转储 HTML源文件: 代码如下:Javascript PhantomJS无法从html源文件生成JPG,javascript,phantomjs,Javascript,Phantomjs,我试图从html源代码生成JPG图像,但脚本甚至生成了0KB的JPG文件 状态=成功 此html源没有错误日志 同样的脚本也适用于其他html源转储 HTML源文件: 代码如下: var page = require('webpage').create(), fs = require('fs'), address = "dump.html"; page.onError = function(msg, trace) { var msgStack = ['ERROR: ' + msg]; if
var page = require('webpage').create(), fs = require('fs'),
address = "dump.html";
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'));
};
console.log('isFile? ' + fs.isFile(address));
console.log('isReadable? ' + fs.isReadable(address));
page.open(address, function(status){
console.log('status? ' + status);
page.render('example.jpg');
phantom.exit();
});
我通过html验证程序运行了它。您的html中似乎有错误。但在浏览器中它会正确呈现。有什么最好的方法来改进它吗?