title: phantomjs - execute a Javascript function after page load and then output new changes
body: <p>I use phantomjs 2.1.1 and something is bothering me.
  Here is the piece of code that I use for scraping a url and the html of the website is written into output.html file </p>
  
  <pre><code>page = require('webpage').create();
      page.open(url, function (status) {
          if (status !== 'success') {
              console.log('Unable to load the address!');
              phantom.exit();
          } else {
              window.setTimeout(function () {
                  var content = page.content;
                  fs.write("output.html", content, 'w');
              }, 40000); //40 seconds timeout
          }
      });
  </code></pre>
  
  <p>Now, I need to scrape its paginations too. The next pages are loaded by a javascript function page(2); or page(3); I tried to get it done using </p>
  
  <pre><code> var pageinationOutput = page.evaluate(function (s) {
      page(2);
   });
   console.log(pageinationOutput); // I need the output made by the  `page(2);` call.
  
          page = require('webpage').create();
              page.open(url, function (status) {
                  if (status !== 'success') {
                      console.log('Unable to load the address!');
                      phantom.exit();
                  } else {
                      window.setTimeout(function () {
                          var content = page.content;
                          fs.write("output.html", content, 'w');
                      }, 40000); //40 seconds timeout
                  }
              });
  </code></pre>
  
  <p>But i am not getting any outputs for this.
  How can I execute a JavaScript function after a page is finished loading and get the <strong>new changes</strong> that has happened to the website contents after the javascript exec, in this case website will call the next page (using ajax) after page(2); method call.</p>
  
  <p>Thanks in advance!</p>