casperjs错误:从node.js运行时,casper没有方法启动

运行最简单的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();

节点:js版本 – v0.10.22
CasperJS版本1.1.0-beta3在/usr/local/lib / node_modules / casperjs,使用phantomjs版本1.9.2
主机操作系统是OSX 10.8.5

最佳答案 来自CasperJS FAQ:

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.

Source

点赞