title: Phantomjs get link and click it
body: <p>I'm trying to scrape one page and get 1 link to a file to download.
  The problem is that download link works only if server recognize referer of the source of file.</p>
  
  <p>I tried to download it with Curl on a php script with referer setted, but it didn't work.</p>
  
  <p>So, I tried with PhantomJS that works like a browser but I can't find the link where I need to click on it. I tried to set manually as target url the download link and as referer the origin url, but I still have error.</p>
  
  <p>I login to that site with this code:</p>
  
  <pre><code>var pageLogin = require('webpage').create(),
  server = 'http://domain.com/login.php',
  data = 'redirect=index.php&amp;login_username=username&amp;login_password=password&amp;';
  
  pageLogin.open(server, 'post', data, function (status) {
  if (status !== 'success') {
      console.log('Unable to post!');
  } else {
      console.log(pageLogin.content);
  }
  
  });
  </code></pre>
  
  <p>I saved cookie and it works.</p>
  
  <p>Now, I need to load another page, for example:</p>
  
  <pre><code>var pageRelease = require('webpage').create(),
  serverRelease = 'http://domain.com/page.php?t=112';
  </code></pre>
  
  <p>and in this page I need to extract this link:</p>
  
  <pre><code>&lt;tr class="row1"&gt;
      &lt;td width="15%"&gt;aaa:&lt;/td&gt;
      &lt;td width="70%"&gt;aaa &amp;nbsp;&lt;span title="aaa"&gt;[ 13-may-14 15:15 ]&lt;/span&gt;&lt;/td&gt;
      &lt;td width="15%" rowspan="4" class="tCenter pad_6"&gt;
                      &lt;p&gt;&lt;a href="dl.php?t=112" class="dl-stub"&gt;&lt;img src="http://domain.com/templates/default/images/attach_big.gif" /&gt;&lt;/a&gt;&lt;/p&gt;
          &lt;p&gt;&lt;a href="dl.php?t=112" class="dl-stub dl-link"&gt;drink.txt&lt;/a&gt;&lt;/p&gt;
                      &lt;p class="small"&gt;5KB&lt;/p&gt;
          &lt;p style="padding-top: 6px;"&gt;&lt;input id="gir-filelist-btn" type="button" class="lite" style="width: 120px;" value="download" /&gt;&lt;/p&gt;      &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>My problem is that I can't find the href:</p>
  
  <pre><code>    &lt;a href="dl.php?t=112" class="dl-stub dl-link"&gt;drink.txt&lt;/a&gt;
  </code></pre>
  
  <p>I tried with this function but it didn't work:</p>
  
  <pre><code>var results = page.evaluate(function() {
          var allParas = document.getElementsByClassName("dl-stub");
  
  
          var num = allParas.length;
          var title = new Array();
  
          for(var i=0; i &lt; num; i++) {
            title[i] = allParas[i].childNodes[1].childNodes[0].InnerHTML;
          }
  
          return title;
      });
  
      for(var i=0; i &lt; results.length; i++) {
        console.log(results[i]) + "\n";
      }
  </code></pre>
  
  <p>What can I do?</p>
  
  <p>Any suggestion?</p>
  
  <p>Thanks</p>