title: how to result the contents of a javascript variable using cheerio (jquery like selectors, but no dom)
body: <p>There is a large html file with many javascript tags in it. I'm trying to scoop out the contents of that variable. The variable name stays the same but the contents change on every request.</p>
  
  <p>examplefile.html</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;//.... more js&lt;/script&gt;
  &lt;script type="text/javascript"&gt;//.... more js&lt;/script&gt;
  &lt;script type="text/javascript"&gt;var foo = {"b":"bar","c":"cat"}&lt;/script&gt;
  &lt;script type="text/javascript"&gt;//.... more js&lt;/script&gt;
  &lt;script type="text/javascript"&gt;//.... more js&lt;/script&gt;
  &lt;script type="text/javascript"&gt;//.... more js&lt;/script&gt;
  </code></pre>
  
  <p>desired console result</p>
  
  <pre><code>&gt; var result = $('script').&lt;some_selection_thingy&gt;
  result = {"b":"bar","c":"cat"}
  </code></pre>
  
  <p>Let me explain a little bit...
  By  I mean that my questions is - 
  a) how do I select the array object with has the contents 'var foo'
  b) how do I get the contents of the var foo variable so that I can import that information into a local json variable for further processing. </p>
  
  <p>when you run $('script') in the console, jquery returns an array.</p>
  
  <pre><code>&gt; $('script')
  [&lt;script type="text/javascript"&gt;//.... more js&lt;/script&gt;,&lt;script type="text/javascript"&gt;//.... more js&lt;/script&gt;,&lt;script type="text/javascript"&gt;var foo = {"b":"bar","c":"cat"}&lt;/script&gt;,&lt;script type="text/javascript"&gt;...&lt;/script&gt;]
  </code></pre>
  
  <p><strong>Because this is cheerio not actually jquery, the dom isn't loaded so I can't just do $(foo) .</strong>
  There is an alternative that I can use jsdom instead of cheerio but I've read in other stackoverflow responses (while researching this question) that it's less performant so I'd prefer to learn the correct jquery selectors I need to scoop out this variable.</p>
  
  <p>server.js</p>
  
  <pre><code>// some cheerio node code
  url = 'someurl';
  request(url, function(error, response, html){
      var $ = cheerio.load(html);
      result = $('script').map(&amp;:text).select{ |s| s['var foo'] }
      result = result[0]
  //SyntaxError: Unexpected token &amp;
  </code></pre>
  
  <p>Which is of course expected because .map(&amp;:text) is what I'd do if I was using xpath but doesn't work with cheerio (jquery).</p>