窗户上的幻影
我有以下非常简单的代码:
var phantom = require('phantomjs'); phantom.create(function(ph){ ph.createPage(function(page) { page.open("http://www.google.com", function(status) { page.render('google.pdf', function(){ console.log('Page Rendered'); ph.exit(); }); }); }); });
当我运行这个我得到一个undefined is not a function
错误在线phantom.create()
我现在坐在一台Windows机器上,并阅读的地方,我可能不得不使用的东西叫dnode
我的问题是这可能是错误的原因,或者在代码中可能是错误的东西吗?
更新
我已经将var phantom = requiere(phantomjs)
更改为var phantom = requiere(phantom)
,但现在我得到错误:
phantom stderr: 'phantomjs' is not recognised as an internal or external kommand, a program or a batchfil. ... AssertionError: abnormal phantomjs exit code: 1
你在phantomjs
和phantom
node.js模块之间phantomjs
。
您的代码遵循phantom
模块的模式,如下所示: https ://www.npmjs.com/package/phantom(这是phantomjs的节点封装)
所以,需要幽灵,而不是phantomjs
在这之前一定要运行npm install phantom
var phantom = require('phantom'); //not phantomjs phantom.create(function(ph){ ph.createPage(function(page) { page.open("http://www.google.com", function(status) { page.render('google.pdf', function(){ console.log('Page Rendered'); ph.exit(); }); }); }); });