Retrieve html content of a page several seconds after it's loaded
<p>I'm coding a script in nodejs to automatically retrieve data from an online directory.
Knowing that I had never done this, I chose javascript because it is a language I use every day.</p>

<p>I therefore from the few tips I could find on google use request with cheerios to easily access components of dom of the page.
I found and retrieved all the necessary information, the only missing step is to recover the link to the next page except that the one is generated 4 seconds after loading of page and link contains a hash so that this step Is unavoidable.</p>

<p>What I would like to do is to recover dom of page 4-5 seconds after its loading to be able to recover the link</p>

<p>I looked on the internet, and much advice to use PhantomJS for this manipulation, but I can not get it to work after many attempts with node.</p>

<p>This is my code :</p>

<pre><code>#!/usr/bin/env node
require('babel-register');
import request from 'request'
import cheerio from 'cheerio'
import phantom from 'node-phantom'

phantom.create(function(err,ph) {

  return ph.createPage(function(err,page) {

    return page.open(url, function(err,status) {

      console.log("opened site? ", status);
      page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', function(err) {

        //jQuery Loaded.
        //Wait for a bit for AJAX content to load on the page. Here, we are waiting 5 seconds.

        setTimeout(function() {

          return page.evaluate(function() {

            var tt = cheerio.load($this.html())
            console.log(tt)

          }, function(err,result) {

            console.log(result);
            ph.exit();

          });

        }, 5000);

      });
    });
  });
});
</code></pre>

<p>but i get this error : </p>

<blockquote>
  <p>return ph.createPage(function (page) {
              ^</p>
  
  <p>TypeError: ph.createPage is not a function</p>
</blockquote>

<p>Is what I am about to do is the best way to do what I want to do? If not what is the simplest way? If so, where does my error come from?</p>