Casperjs循环执行(重复执行不退出)

var casper = require('casper').create({
       // pageSettings: {
        //    loadImages:  true,
        //    loadPlugins: false
       // },
        logLevel: "info",
        verbose: true
    });
    	var url='http://docs.casperjs.org/en/latest/modules/casper.html#eachthen';
var fs=require('fs');
var  index=0;
casper.userAgent('Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36');
casper.start().repeat(5,function(){
	index++;
casper.open(url);
 this.wait(5000,function(){
           this.echo('wait 5s over!')
          });
casper.then(function() {
   fs.write('casper_'+index+'.html',this.getHTML(),'w');
});
});

casper.run();

  

posted @ 2017-08-01 11:27  公众号python学习开发  阅读(221)  评论(0编辑  收藏  举报