Phantomjs和Casperjs,后台网页抓取和交互
2024-10-11 16:17:08
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'
}
});
//phantom.outputEncoding="gbk";
casper.options.viewportSize = {width: 1680, height: 924};
casper.start('http://bulo.hujiang.com/app/login?source=nbulo&returnurl=/home/');
casper.waitForSelector("form#myform input[name='txtUsername']",
function success() {
this.test.assertExists("form input[name='txtUsername']");
this.fill("form",{
'txtUsername':'shixiaobao17',
'txtPassword':'×××××your password*****'
},false);
this.click("input#btnLogin");
},
function fail() {
this.test.assertExists("form input[name='txtUsername']");
}); casper.waitFor(function check() {
return this.getCurrentUrl().indexOf("bulo.hujiang.com/home")>-1;
}, function then() {
console.log("登录成功!!!!!!!!!!!!");
}).then(function(){
console.log("执行登录后的其它操作!!!!!!!!!!!!");
if(this.exists("#btn_card_do")){
this.click("#btn_card_do");
this.waitForSelector("#my_hb_btn",function success(){
console.log("打卡成功!");
},function fail(){
console.log("打卡失败!");
});
}else{
console.log("今天已经打过卡啦!");
} });
casper.run(function() {this.test.renderResults(true);});
相关资料:http://casperjs.readthedocs.org/en/latest/modules/casper.html
最新文章
- 认识AMD、CMD、UMD、CommonJS
- 耿丹CS16-2班第一次作业汇总
- My Tornado Particle Effect
- [GeekBand] STL与泛型编程(2)
- opengl (1) 基本API的熟悉
- 20169210《Linux内核原理与分析》第四周作业
- inner join跟where查询的区别
- 杂项(最小表示法):HZOI 2015 Glass Beads
- 蓝牙4.0BLE cc2540 usb-dongle的 SmartRF Packet Sniffer 抓取数据方法
- [Javascript] JSON.parse API
- spring、spring mvc、mybatis框架整合基本知识
- js实现分页
- Linux之旅-ubuntu下搭建nodejs环境
- 关于:未能加载文件或程序集“ICSharpCode.SharpZipLib”或它的某一个依赖项异常的解决方案
- RecyclerView联动滑动失败
- RocketMQ事务消息-demo
- iOS8中 UILocalNotification 和 UIRemoteNotification 使用注意
- canvas学习之折线图
- 从概率图模型pgm到rbm
- 2.BIND服务基础及域主服务器配置