如何从phantomjs shell中运行casper?

时间:2012-10-27 15:22:09

标签: phantomjs casperjs

任何人都知道是否以及如何从phantomjs shell中运行casperjs(a.k.a InteractiveModeREPL )?

phantomjs shell

我也尝试将直接路径传递给casper.js模块,但也没有用。

进度/更新

  • 尝试phantomjs.injectJs('C:/casperjs/module/casper.js');但得到Error: Cannot find module 'colorizer'我想我已经接近了。
  • 这让我更接近但仍然缺少路径:
    • phantomjs.injectJs('C:/casperjs/module/bin/bootstrap.js')
      • Cannot find package.json at C:/package.json
      • 出错
    • 好的,看起来我可以在启动phantomjs时传递--casper-path选项(参见 - casper / bin / bootstrap.js:第189行)。
    • 好的,有效。 (传递选项不起作用,但设置了幻影内部的路径)。

1 个答案:

答案 0 :(得分:3)

首先,要让这些东西在phantomjs shell中运行,你需要在幻像全局对象中设置一个casperPath变量。

phantom.casperPath = "C:/casper";

然后你需要inJect caspers的bootstrap.js文件。

phantom.injectJs("C:/casper/bin/bootstrap.js");

现在你可以实例化一个casper对象并在shell中使用它。

var casper = require("casper").create();

享受。

相关问题