0

我正在使用 Node.js 和可用的节点幻象模块。但我似乎被困在一个基本的水平,无法让这段基本的代码工作:

var phantom = require('phantom');
phantom.create(function(ph) {
  return ph.createPage(function(page) {
    return page.open("http://www.google.com", function(status) {
      console.log("opened google? ", status);
      return page.evaluate((function() {
        return document.title;
      }), function(result) {
        console.log('Page title is ' + result);
        return ph.exit();
      });
    });
  });
});

我真的不明白为什么控制台消息没有出现?我猜这恰好在某个幻影范围内,但是我可以将消息解析到节点上吗?还是问题完全不同?

4

1 回答 1

0

从自述文件:

首先,确保安装了 PhantomJS。该模块期望 phantomjs 二进制文件位于 PATH 某处。换句话说,输入这个:

$ phantomjs

如果这样可行,那么 phantomjs-node 也可以。它仅在 PhantomJS 1.3 上进行过测试,几乎可以肯定不适用于任何较旧的版本。

如果这不起作用(我所期望的)安装 phantomjs:http ://phantomjs.org/download.html

于 2013-03-27T12:58:23.100 回答