1. 安装PhantomJS(CasperJS 依赖于PhantomJS >= 1.3)
解压安装:https://code.google.com/archive/p/phantomjs/wikis/Installation.wiki
文件解压到~目录下,配置环境变量:
export PATH="$PATH:/Users/yujiaxi/phantomjs-2.1.1-macosx/bin"
查看是否安装成功:phantomjs —version 输出2.1.1
2. 安装casperjs:
git clone git://github.com/n1k0/casperjs.git
cd casperjs
git checkout tags/0.6.9
ln -sf `pwd`/bin/casperjs /usr/local/bin/casperjs
查看是否安装成功:casperjs —version
并没有返回版本号,返回信息:CasperJS needs at least PhantomJS v1.5.0
但是我的phantomjs是2.x?

if (phantom.version.major !== 1 || phantom.version.minor < 5) {
console.error('CasperJS needs at least PhantomJS v1.5.0');
phantom.exit(1);
}
替换成:
var system = require('system');
var argsdeprecated = system.args;
argsdeprecated.shift();
phantom.args = argsdeprecated;
(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);
然后就可以

网友评论