【发布时间】:2012-06-25 20:45:17
【问题描述】:
我有一个 nodejs 脚本,它使用 phantomjs-node 来抓取网页。当我从终端窗口运行时,它工作正常,但当我通过 Node JS 应用程序的运行配置从 Webstorm 内部运行时,它就不行了。
什么可能导致 Webstorm 中的错误?
在注释掉 .bash_profile 的内容后,我已经尝试从终端运行脚本,它仍然有效。我还在另一个示例脚本中检查了 process.env 的内容,发现 Webstorm 与终端中的值完全不同。
脚本:
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();
});
});
});
});
终端输出(效果很好!):
opened google? success
Page title is Google
Webstorm 控制台输出(失败):
/usr/local/bin/node phantom.js
phantom stderr: execvp(): No such file or directory
Process finished with exit code 0
【问题讨论】:
-
如果您使用的是 Mac,请检查以下问题:apple.stackexchange.com/q/51677。
标签: node.js terminal phantomjs webstorm