Javascript Zombie.js返回不正确的页面内容

Javascript Zombie.js返回不正确的页面内容,javascript,http,node.js,zombie.js,Javascript,Http,Node.js,Zombie.js,我是僵尸新手,只是想做一个基本的测试。我有以下代码: 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

我是僵尸新手,只是想做一个基本的测试。我有以下代码:

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
摘自:


但我仍然想知道Zombie出了什么问题,因为我想在其他项目上使用它进行测试。

Browser是通过require加载的类。您希望创建一个作为浏览器实例的变量,然后使用该变量调用visit。您的代码应该是:

var Browser = require('zombie');

var startTime = +new Date();

my_browser = new Browser(); // Here's where you need to call new
my_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);
});

现在,我升级到Node.js和Zombie.js的新版本后,它似乎可以工作了。请注意,您不能将Node的预版本与zombie.js一起使用(其中一个依赖项会失败)


使用NVM安装最新的稳定版本(撰写本文时为0.8.9版)。

感谢您的快速回答。但不,不是这样。我试过了。你是说新浏览器()。它不是ruby:)。此外,visit方法创建一个实例并将其传递回回调,因此这不是问题所在。我想可能是Ubuntu上的安装。
var Browser = require('zombie');

var startTime = +new Date();

my_browser = new Browser(); // Here's where you need to call new
my_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);
});