您的位置:首页 > 编程语言 > ASP

mac 下安装 CASPERJS

2015-04-29 10:16 302 查看

安装

brew install casperjs

安装完成后使用

1. phantomjs –version

2. casperjs –version

查看安装的版本

因为 phantomjs 2.00对支持 casperjs 有问题

需要修改

/usr/local/homebrew/Cellar/casperjs/1.0.4/libexec/bin/bootstrap.js 增加一段代码

var system = require('system');
var argsdeprecated = system.args;
argsdeprecated.shift();
phantom.args = argsdeprecated;


实例代码,登陆人人

//登陆人人
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
pageSettings: {
loadImages:  false,
loadPlugins: true,
userAgent: 'Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0'
}
});
casper.options.viewportSize = {width: 1680, height: 924};
casper.start('http://www.renren.com');
casper.waitForSelector("form#loginForm",
function success() {
this.test.assertExists("form input[name='email']");
this.fill('form[id="loginForm"]',{
'email':'your name'
'password':'your pass'
},false);
this.click("input#login");
},
function fail() {
this.test.assertExists("form input[name='email']");
});

casper.waitFor(function check() {
return this.getCurrentUrl().indexOf("www.renren.com/***")>-1;
}, function then() {
console.log("登录成功!!!!!!!!!!!!");
}).then(function(){
console.log("执行登录后的其它操作!!!!!!!!!!!!");
console.log("打开链接并截图");
this.capture("./renren.png");
});
casper.run(function() {this.test.renderResults(true);});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  casperjs