为什么此代码会导致使用幻影模块的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(); }); }); }); }); 

对此:

  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.get('title',(function(title) { return title; }), function(result) { console.log('Page title is ' + result); return ph.exit(); }); }); }); }); 

打印后,节点在控制台挂起“打开谷歌? 成功',没有进一步的产出。

我正在尝试使用page.get()而不是page.evaluate,如幻影模块文档中所述 :

属性不能直接获取/设置,而是使用p.get('version',callback)

你滥用page.get() 。 这个方法只有两个参数,而不是三个。

这是如何做到的:

 page.get('title', function(title) { console.log('Page title is ' + title); return ph.exit(); });