请参阅下面的代码。
我想捕获两个网页。
使用 phantomjs 运行这段代码后,我只得到了一张网页截图(www.baidu.com)。
phantomjs 中的网页是单例的吗?我可以在一个 phantomjs 实例中打开两个网页吗?
var webpage1 = require('webpage').create();
webpage1.onLoadFinished = function() {
webpage1.render('1.png');
}
webpage1.open('http://www.google.com');
var webpage2 = require('webpage').create();
webpage2.onLoadFinished = function() {
webpage2.render('2.png');
}
webpage2.open('http://www.baidu.com');
更新:
谢谢@Cybermaxs
我延迟了脚本的结束,它有效。我有两个截图。
var webpage1 = require('webpage').create();
webpage1.onLoadFinished = function() {
webpage1.render('1.png');
}
webpage1.open('http://www.google.com.cn');
var webpage2 = require('webpage').create();
webpage2.onLoadFinished = function() {
webpage2.render('2.png');
}
webpage2.open('http://www.baidu.com');
setTimeout(function() {
console.log(webpage1.url);
console.log(webpage2.url);
phantom.exit(0);
}, 9000);