2012-10-27 41 views
0

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

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
    • OK,貌似开始phantomjs时,我可以通过--casper路径选项(见 - casper/bin/bootstrap.js:189行)。
    • 确定工作。 (通过选项不起作用,但在幻影内部设置路径)。

回答

3

所以得到这个东西运行里面的phantomjs shell首先你需要设置在幻影全球对象casperPath变量。

phantom.casperPath = "C:/casper";

然后你需要注入卡斯佩斯的bootstrap.js文件。

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

现在你可以实例化一个卡斯帕尔对象,并在外壳用它玩。

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

享受。

+0

不再有效。见[casper 1.1升级](http://docs.casperjs.org/en/latest/upgrading/1.1.html)和[更新的问题](http://stackoverflow.com/questions/19857139/running-casperjs -test合虚线)。 –

+0

它不适合我。 phantomjs 1.9.8不再具有可变的casperPath。 –

+0

在2016年有与casper-1.1.1和phantomjs 1.9.1交互模式的任何解决方法? –