title: How to Handle redirects in Node.JS with HorsemanJs and PhantomJS
body: <p>I´ve recently started using horseman.js to scrap a page with node. I can´t figure out how exactly it works and I can´t find good examples on the internet.</p>
  
  <p>My main goal is to log on a platform and extract some data. I´ve managed to do this with PhantomJS, but know I want to learn how to do it with horseman.JS.</p>
  
  <p>My code should open the login page, fill the login and password inputs and click on the "login" button. Pretty easy so far. However, after clicking on the "login" button the site makes 2 redirects before loading the actual page where I want to work.</p>
  
  <p>My problem is that I don´t know how to make my code wait for that page.</p>
  
  <p>With phantomJS I had a workaround with the page URL. The following code shows how I´ve managed to do it with phantomJS and it works just fine:</p>
  
  <pre><code>var page = require('webpage').create();
  
  var urlHome = 'http://akna.com.br/site/montatela.php?t=acesse&amp;header=n&amp;footer=n';
  
  var fillLoginInfo = function(){
      $('#cmpLogin').val('mylogin');
      $('#cmpSenha').val('mypassword');
      $('.btn.btn-default').click();
  };
  
  page.onLoadFinished = function(){
  
      var url = page.url;
      console.log("Page Loaded: " + url);
  
      if(url == urlHome){
          page.evaluate(fillLoginInfo);
          return;
      }
  
     // After the redirects the url has a "sid" parameter, I wait for that to apear when the page loads.
     else if(url.indexOf("sid=") &gt;0){
      //Keep struggling with more codes!
      return;
  }
  
  }
  
  page.open(urlHome);
  </code></pre>
  
  <p>However, I can´t find a way to handle the redirects with horseman.JS.</p>
  
  <p>Here is what I´ve been trying with horseman.JS without any success:</p>
  
  <pre><code>var Horseman = require("node-horseman");
  var horseman = new Horseman();
  
  var urlHome = 'http://akna.com.br/site/montatela.php?t=acesse&amp;header=n&amp;footer=n';
  
  var fillLoginInfo = function(){
    $('#cmpLogin').val('myemail');
    $('#cmpSenha').val('mypassword');
    $('.btn.btn-default').click();
  }
  
  var okStatus = function(){
    return horseman.status();
  }
  
  horseman
    .open(urlHome)
    .type('input[name="cmpLogin"]','myemail')
    .type('input[name="cmpSenha"]','mypassword')
    .click('.btn-success')
    .waitFor(okStatus, 200)
    .screenshot('image.png')
    .close();
  </code></pre>
  
  <p>How do I handle the redirects?</p>