如何在 CasperJS 中使用文件 运行 中的 NPM 模块?
How to use NPM modules in file run with CasperJS?
我知道 CasperJS 不能直接与节点一起使用,但我什至不能使用像 cheerio
这样的服务,一个节点网络抓取工具吗?
我试了require('cheerio');
,它说找不到。所以,我做了:
proxies/cheerios.js
module.exports = require('cheerio');
tests/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 不工作...
它 运行 在 PhantomJS 之上,所以如果你想包含外部库,你需要 inject 它们到你的代码中。
我知道 CasperJS 不能直接与节点一起使用,但我什至不能使用像 cheerio
这样的服务,一个节点网络抓取工具吗?
我试了require('cheerio');
,它说找不到。所以,我做了:
proxies/cheerios.js
module.exports = require('cheerio');
tests/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 不工作...
它 运行 在 PhantomJS 之上,所以如果你想包含外部库,你需要 inject 它们到你的代码中。