2015-08-28 56 views
1

我知道CasperJS不能直接与节点一起使用,但我可以不使用像节点网络抓取工具cheerio这样的服务吗?我试过require('cheerio');,它说没有找到。所以,我所做的:如何在使用CasperJS的文件中使用NPM模块?

代理/ cheerios.js

module.exports = require('cheerio'); 

测试/ file.js

var cheerio = require('../proxies/cheerio.js'); 

现在,我得到:

Error: Cannot find module 'util'

phantomjs://bootstrap.js:289

phantomjs://bootstrap.js:254 in require

任何建议?我真的需要在CasperJS中使用这个插件,并且SpookyJS不工作...

回答

1

它运行在顶级PhantomJS上,所以如果你想包含外部库,你需要将它们inject加入你的代码中。

+0

这不是我想要的,但c'est la vie ...您可以注入jQuery并使用它而不是cheerio ...谢谢。 – user1947561

相关问题