2013-03-26 35 views
0

我在玩Node.js和可用的节点幻像模块。但我似乎在基本层面上被卡住,并不能得到这个代码基础件工作: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(); 
     }); 
    }); 
    }); 
}); 

我真的不能明白,为什么控制台消息不会出现?我想,这恰好在某个幻像范围内,但是我可能会将这些消息解析到节点上吗?还是问题完全是其他问题?

+0

也许没有加载幻象..你尝试之后 phantom.create(函数(PH){或pH值的console.log。 createPage(function(page){ – ZimSystem 2013-03-26 15:11:50

+0

)还要确保在幻像需要的库中没有x86_64与i686的不匹配。请参阅我的答案:http://stackoverflow.com/questions/17002351/node-phantom -createpage-never-calls-callback/17137960#17137960 – hoonto 2013-06-16 21:56:02

回答

0

自述:

首先,确保PhantomJS安装。该模块预计phantomjs二进制文件位于PATH的某处。换句话说,键入:

$ phantomjs 

如果这样的话,phantomjs-node也会起作用。它只在PhantomJS 1.3上进行过测试,几乎可以肯定不会与任何老版本兼容。

如果不工作(我希望)安装phantomjs:http://phantomjs.org/download.html

+0

PhantomJS已安装,我切换到'node-phantom'节点包,我没有遇到任何问题。 – 2013-03-29 16:33:18