Javascript 为什么我的phantomjs脚本不输出屏幕截图(命令行args版本)
我在这里修改了基本的phantomjs示例,以接受命令行参数 当我作为参数传递时,console.log输出是正确的 0:index.js 1: 但是我的文件夹中没有任何缩略图.png为什么Javascript 为什么我的phantomjs脚本不输出屏幕截图(命令行args版本),javascript,phantomjs,Javascript,Phantomjs,我在这里修改了基本的phantomjs示例,以接受命令行参数 当我作为参数传递时,console.log输出是正确的 0:index.js 1: 但是我的文件夹中没有任何缩略图.png为什么 var page = require('webpage').create(); var system = require('system'); var args = system.args; var url; if (args.length === 1) {
var page = require('webpage').create();
var system = require('system');
var args = system.args;
var url;
if (args.length === 1) {
url = 'http://github.com/';
} else {
args.forEach(function(arg, i) {
console.log(i + ': ' + arg);
if (i > 0) {
page.open(arg, function() {
page.render('thumbnail' + '.png');
});
}
});
}
phantom.exit();
page.open
是一个异步函数,因此在回调之前会调用phantom.exit
,以呈现缩略图
移动phantom。按照文档中的指定,在回调中退出
var page = require('webpage').create();
page.open('http://github.com/', function() {
page.render('github.png');
phantom.exit();
});