美文网首页
CasperJS with Recursion (Using S

CasperJS with Recursion (Using S

作者: RoyTien | 来源:发表于2017-06-19 11:37 被阅读17次
    function getUrlArr(){
      return urlArray;
    }
    
    function recursionFunction(){
      while(){
        var url = Stack.pop();
      }
    
      if(){
        casper.thenOpen(url, function() {
          output(Information);
        }
        if(Stack.lenght > 0){
          // Recursion
          recursionFunction();
        }
      }else{
        output(Information);
        casper.thenOpen(currentUrl, function() {
          var urlArray = this.evaluate(getUrlArr);
          this.each(urlArray, function(self, url) {
            Stack.push(url);
          });
          if(Stack.lenght > 0){
            // Recursion
            recursionFunction();
          }
        });
      }
    }
    
    (function() {
      // Declare Stack, IMPORTANT, there is no 'var'
      Stack = [];
    
      // Init CasperJS
      casper = require('casper').create({});
      casper.start(urlLogin, function() {
      });
    
      // Init Stack and Start Recursion, and function in recursion CAN USE Stack
      Stack.push(url);
      recursionFunction();
    
      // Ending
      casper.run(function() {
        this.echo("Finished running ...");
        return this.exit();
      });
    }).call(this);
    

    相关文章

      网友评论

          本文标题:CasperJS with Recursion (Using S

          本文链接:https://www.haomeiwen.com/subject/gclgqxtx.html