运行最简单的 casperjs 示例会出现错误:
casper.start('http://casperjs.org/', function() {
^
TypeError: Object function (req, res) {
var raw = new Model(data || (allowBody ? req.body : {}));
raw.save(cb || function (err, obj) {
if (err) return res.jsonp(500, err);
res.jsonp(obj);
});
} has no method 'start'
at Object.<anonymous> (/Users/path/to/main.js:16:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
我正在运行的代码是:
var utils = require('utils');
var casper = require('casper').create();
casper.start('http://casperjs.org/', function() {
this.echo(this.getTitle());
});
casper.thenOpen('http://phantomjs.org', function() {
this.echo(this.getTitle());
});
casper.run();
Node:js 版本 - v0.10.22 CasperJS 版本 1.1.0-beta3 在/usr/local/lib/node_modules/casperjs,使用 phantomjs 版本 1.9.2 主机操作系统是 OSX 10.8.5
最佳答案
来自 CasperJS 常见问题解答:
Is CasperJS a node.js library? No. CasperJS is written on top of PhantomJS, which is a node-independent Qt/WebKit based library. If you try to run your CasperJS script with node, it just won’t work out of the box.
Hint: If you want to drive CasperJS from node, try SpookyJS.
关于node.js - casperjs 错误 : casper has no method start when running from node. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20909611/