遇到的问题如题:
首先,安装完成后,直接运行报错如下:
1
|
CasperJS needs PhantomJS v1.x |
解决方式,去掉casperjs的版本限制代码,代码所在目录casperjs\bin\bootstrap.js,要去掉的代码,当然你也可以替换成下:
1
2
3
4
5
6
7
8
9
10
11
12
|
//需删除或替换的代码块 ( function (version) { // required version check if (version.major !== 1) { return __die( ‘CasperJS needs PhantomJS v1.x‘ ); } if (version.minor < 8) { return __die( ‘CasperJS needs at least PhantomJS v1.8 or later.‘ ); } if (version.minor === 8 && version.patch < 1) { return __die( ‘CasperJS needs at least PhantomJS v1.8.1 or later.‘ ); } })(phantom.version); |
若是替换,可用下面代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
( function (version) { // required version check if (version.major === 1) { if (version.minor < 8) { return __die( ‘CasperJS needs at least PhantomJS v1.8 or later.‘ ); } if (version.minor === 8 && version.patch < 1) { return __die( ‘CasperJS needs at least PhantomJS v1.8.1 or later.‘ ); } } else if (version.major === 2) { console.log( "Warning PhantomJS v2.0 not yet released. There will not be any official support for any bugs until stable version is released!" ); } else return __die( ‘CasperJS needs PhantomJS v1.x or v2.x‘ ); })(phantom.version); |
操作完成后,再次运行发现又出了如下错误:
1
|
Couldn‘t find nor compute phantom.casperPath, exiting. |
还是需要修改上面的casperjs\bin\bootstrap.js文件,在文件上方加上如下代码:
1
2
3
4
|
var system = require( ‘system‘ ); var argsdeprecated = system.args; argsdeprecated.shift(); phantom.args = argsdeprecated; |
至此,可以正常运行了!
参考文章:
http://stackoverflow.com/questions/28656768/issues-running-casperjs-with-phantomjs2-0-0-on-mac-yosemite
https://github.com/n1k0/casperjs/issues/1150