title: Grab JavaScript console output with PhantomJS and evaluate it
body: <p>I'm trying to parse the status page of my router to get the number of wlan devices. The page uses some JavaScript to get the status, so I tried to use PhantomJS, but had no luck.</p>
  
  <p>This is the html source of the status page (status.html and status.js): <a href="http://pastebin.com/dmvptBqv" rel="nofollow">http://pastebin.com/dmvptBqv</a></p>
  
  <p>The developer tools of my browser show me this output on the console (anonymized): </p>
  
  <pre>
  ([
  {"vartype":"value","varid":"device_name","varvalue":"Speedport W 921V"},
  {"vartype":"value","varid":"factorydefault","varvalue":"1"},
  {"vartype":"value","varid":"rebooting","varvalue":"0"},
  {"vartype":"value","varid":"router_state","varvalue":"OK"},
  {"vartype":"value","varid":"bngscrat","varvalue":"0"},
  {"vartype":"value","varid":"acsreach","varvalue":"0"},
  </pre>
  
  <p><a href="http://pastebin.com/EdWBV77c" rel="nofollow">Full reference</a></p>
  
  <p>How can I get this evaluated output out of PhantomJS? Maybe it is very simple and I just missed the part in the documentation.</p>
  
  <p>I think that i have to use the evluate function, but have no idea what is the correct function for the document object to return the complete evaluation.</p>
  
  <pre><code>var webPage = require('webpage');
  var page = webPage.create();
  
  page.open('blubb', function   (status) {
  
    var js= page.evaluate(function() {
      return document.???;
    });
  
    console.log(js);
    phantom.exit();
  
  });
  </code></pre>