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

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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。