20
我正在評估phantom.js和zombie.js。我期望這種折衷是因爲幻影擁有更廣泛的文檔支持(因爲它使用真實的渲染器),而殭屍更快(因爲不使用渲染引擎)。不過殭屍在我的測試中似乎慢得多。這有意義嗎? ())(我使用casperjs),讓我繼續而不用等待,直到幻像返回(包括運行所有腳本和加載css)之前立即返回整頁。phantom.js vs zombie.js的表現
Phantom.js
casper.userAgent("Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13");
casper.test.begin('bing search', 2, function(test) {
casper.start('http://www.bing.com/', function() {
this.waitUntilVisible('#sb_form_q', function() {
this.sendKeys('#sb_form_q', "book", true);
this.click('#sb_form_go');
this.waitUntilVisible('#count', function() {
var val = this.evaluate(function() {
return document.getElementById('count').innerText
});
console.log(val)
});
});
}).run(function() {
test.done();
});
});
Zombie.js
var Browser = require("zombie");
var browser = new Browser()
browser.userAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13"
browser.visit("http://www.bing.com/", function() {
browser.fill("#sb_form_q", "book");
browser.pressButton("#sb_form_go");
function resultArrived(window) {
return window.document.querySelector("#count")
}
browser.wait(resultArrived, function() {
console.log(browser.document.querySelector("#count").innerHTML)
});
});