如果我改变这个:
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();
});
});
});
});
打印“opened google?”后, Node 卡在控制台上success'并且没有进一步的输出。
我正在尝试使用 page.get() 而不是 page.evaluate,如幻影模块 docs 中所述。 :
Properties can't be get/set directly, instead use p.get('version', callback)
最佳答案
您滥用了page.get()
。该方法只有两个参数,而不是三个。
具体操作方法如下:
page.get('title', function(title) {
console.log('Page title is ' + title);
return ph.exit();
});
关于javascript - 为什么这段代码会导致 Node.js 使用 phantom 模块挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20118511/