title: Having problems structuring Cheerio scraping
body: <p>I think this may be just basic syntax.  I'm coming from Java and very new to Javascript.  For example, when I see a $ in all the examples, my mind goes blank.</p>
  
  <p>Code for parsing the HTTP request (which contains a bunch of dog shows) looks like (using the request library):</p>
  
  <pre><code>function parseRequest1(error, response, body) {
      // TODO  should check for error...
      var Cheerio = require('cheerio');
      parser = Cheerio.load(body);
  
      var table2 = parser('.qs_table[bgcolor="#71828A"]');
      var showList = [];
  
      // skip over a bunch of crap to find the table.  Each row with this BG color represents a dog show
      var trows = parser('tr[bgcolor="#FFFFFF"]', table2);
      trows.each(function(i, tablerow) {
          var show = parseShow(tablerow);
          if (show)  // returns a null if something went wrong
              showList.push(show);
      });
  
      // then do something with showList...
  
  }
  </code></pre>
  
  <p>which is called by</p>
  
  <pre><code>Request.get(URL, parseRequest1);
  </code></pre>
  
  <p>So far, so good.  Where I'm stuck is in how to write the parseShow function.  I'd like to go something like</p>
  
  <pre><code>function parseShow(tableRow) {
      var tds = parser('td', tableRow);
      //and then go through the tds scraping info...
  }
  </code></pre>
  
  <p>but I get an error:  </p>
  
  <pre><code>TypeError: Object #&lt;Object&gt; has no method 'find'
      at new module.exports (C:\Users\Morgan\WebstormProjects\agility\node_modules\cheerio\lib\cheerio.js:76:18)
      at exports.load.initialize (C:\Users\Morgan\WebstormProjects\agility\node_modules\cheerio\lib\static.js:19:12)
      at parseShow (C:\Users\Morgan\WebstormProjects\agility\routes\akc.js:20:15)
  </code></pre>
  
  <p>Looking at the stack trace, it looks like Cheerio is creating a new one.  How am I supposed to pass the Cheerio parser down to the second function?  Right now parser is a global var in the file.</p>
  
  <p>I've tried a bunch of random things like these but they don't work either:</p>
  
  <pre><code>var tds = tableRow('td');
  var tds = Cheerio('td', tableRow);
  </code></pre>
  
  <p>What I'm forced to do instead is a bunch of disgusting, fragile code accessing <code>tableRow.children[1], tableRow.children[3]</code>, etc...  (the HTML has /r/ns all over creation so many of the children are whitespace)</p>