title: Accessing values of JS Global variables in HTML with PhantomJS
body: <p>So I have a piece of HTML that looks something like this:</p>
  
  <pre><code>&lt;html&gt;
    &lt;body&gt;
      &lt;script&gt;
        var foo = {
          bar: []
        };
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And I am trying to use PhantomJS to extract the value of foo.bar. How would I do this? So far I know I would have is structured like this: </p>
  
  <pre><code>var webPage = require('webpage'); 
  var page = webPage.create();
  page.open(MY_URL, function(status) {
    var foo = page.evaluate(function(){
      //gets javascript from the HTML in the response
      // and extracts foo from there
    });
  });
  
  console.log(someVar);
  phantom.exit();
  </code></pre>