Node.js和幻像问题

时间:2013-03-26 12:51:08

标签: javascript node.js web-scraping phantomjs

我正在玩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();
      });
    });
  });
});

我无法弄清楚为什么控制台消息不会出现?我想这恰好在某些幻像范围内,但是我可以将消息解析到节点吗?或者问题是完全不同的吗?

1 个答案:

答案 0 :(得分:0)

自述文件:

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

$ phantomjs

如果有效,phantomjs-node也是如此。它仅使用PhantomJS 1.3进行测试,几乎可以肯定不适用于任何旧版本。

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