码迷,mamicode.com
首页 > Web开发 > 详细

Phantomjs和Casperjs,后台网页抓取和交互

时间:2014-09-28 15:10:22      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   os   ar   java   for   sp   div   

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

Phantomjs和Casperjs,后台网页抓取和交互

标签:blog   http   io   os   ar   java   for   sp   div   

原文地址:http://www.cnblogs.com/jamesbd/p/3998031.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!