我有一个nodejs脚本,它使用phantomjs-node来抓取网页。当我从终端窗口运行时,它工作正常,但是当我通过Node JS应用程序的运行配置从Webstorm内部运行时,它工作正常。脚本在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上,请检查以下问题:http://apple.stackexchange.com/q/51677。 – CrazyCoder