title: CasperJS looping through each URL
body: <p>This question is <a href="https://stackoverflow.com/questions/24360993/casperjs-iterating-through-urls">similar</a> <a href="https://stackoverflow.com/questions/23384963/casperjs-loop-or-iterate-through-multiple-web-pages">to</a> <a href="https://stackoverflow.com/questions/28421307/how-to-tell-casperjs-to-loop-through-a-series-of-pages">others</a>, but the problem I had was more basic.</p>
  
  <p>This is my code:</p>
  
  <pre><code>var links = [];
  var casper = require('casper').create();
  
  function getLinks() {
      var links = document.querySelectorAll('div#mw-content-text table.wikitable tbody tr td i b a');
      return Array.prototype.map.call(links, function(e) {
          return 'https://en.wikipedia.org' + e.getAttribute('href');
      });
  }
  
  casper.start('https://en.wikipedia.org/wiki/David_Bowie_discography');
  
  casper.then(function() {
      // aggregate results for the 'casperjs' search
      links = this.evaluate(getLinks);
  });
  
  casper.each(links, function (self, link) {
      self.thenOpen(fullURL, function () {
          this.echo(this.getTitle() + " - " + link);
      });
  });
  
  casper.run();
  </code></pre>
  
  <p>I know that <code>links</code> get created as it is copied from the <a href="http://docs.casperjs.org/en/latest/quickstart.html#now-let-s-scrape-google" rel="nofollow noreferrer">Quickstart</a>, but I then modified it to open all the links that were found.</p>
  
  <p>What I'm getting is that nothing is echo'd instead of outputting the each title which is what I expect. This is how I'm calling the file:</p>
  
  <pre><code>~ $ casperjs casper-google-disco.js
  </code></pre>