我是僵尸新手,只是想运行一个基本的测试。我有以下代码:
var Browser = require('zombie');
var startTime = +new Date();
Browser.visit("http://zombie.labnotes.org/", function(e, browser) {
var duration;
console.log("Successfully visted the page");
console.log(browser.html());
duration = (+(new Date())) - startTime;
console.log("Finished in (milliseconds): " + duration);
});
出于某种原因,我在控制台中得到的只是:
成功访问页面
<html>
<head></head>
<body></body>
</html>
Finished in (milliseconds): 5020
这显然不是正确的标记,并且需要相当长的时间(5 秒)才能做到这一点。有任何想法吗?
更新:最终使用 request 和 jsdom 切换到更简单的模型。这是我使用的代码: var request = require('request'), jsdom = require('jsdom');
//Tell the request that we want to fetch youtube.com, send the results to a callback function
request({uri: 'http://youtube.com'}, function(err, response, body){
var self = this;
self.items = [];
//Just a basic error check
if(err && response.statusCode !== 200){console.log('Request error.');}
//Send the body param as the HTML code we will parse in jsdom
//also tell jsdom to attach jQuery in the scripts and loaded from jQuery.com
jsdom.env({
html: body,
scripts: ['http://code.jquery.com/jquery-1.6.min.js']
}, function(err, window){
//Use jQuery just as in a regular HTML page
var $ = window.jQuery;
console.log(body);
});
});
取自: http: //net.tutsplus.com/tutorials/javascript-ajax/how-to-scrape-web-pages-with-node-js-and-jquery/
但我仍然想知道 Zombie 出了什么问题,因为我想用它来测试其他项目。