node.js - casperjs 错误 : casper has no method start when running from node. js

标签 node.js casperjs

运行最简单的 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.

Source

关于node.js - casperjs 错误 : casper has no method start when running from node. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20909611/

相关文章:

javascript - 使用casperjs时如何等待页面加载?

javascript - 是否可以使用 spookyjs 从 casperjs 范围内的 Node 范围调用评估函数?

node.js - Electron 重建 grpc 构建失败

javascript - 如何用 Electron 打开 React 的屏幕?

javascript - 请求对象和响应对象

javascript - 如何将 SSL 证书添加到我现有的 node.js 服务器?

javascript - 当抓取 Google 搜索时更改设置特定用户代理字符串时,CasperJS 返回不同的结果

windows - Casper CLI 选项不处理 Windows 上的空格

casperjs - 从 cron 运行 CasperJS

ruby - 使用 ruby​​ 的特定 dom 元素的屏幕截图