title: Parse HTML table without IDs or CSS selectors in Node.js
body: <p>This data is from an old system and the output is as is. We cannot add CSS selectors or IDs. Most of the examples online for node.js parsing involves parsing tables, rows, data with some ID or CSS classes but so far I haven't run into anything that can help parse the page below. This includes examples for JSDOM (AFAIK). </p>
  
  <p>What I would like is to extract each of the rows into [fileName, link, size, dateTime] tuples on which I can then run some queries like what was the latest timestamp in the group, etc and then extract the filename and link - was thinking of using YQL. The alternating table row attributes is also making it a bit challenging. New to node.js so some of the terminology might be wrong. Any help will be appreciated.</p>
  
  <p>Thanks.</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;table width="100%" cellspacing="0" cellpadding="5" align="center"&gt;
          &lt;tr&gt; 
          &lt;td align="left"&gt;&lt;font size="+1"&gt;&lt;strong&gt;Filename&lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
          &lt;td align="center"&gt;&lt;font size="+1"&gt;&lt;strong&gt;Size&lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
          &lt;td align="right"&gt;&lt;font size="+1"&gt;&lt;strong&gt;Last Modified&lt;/strong&gt;&lt;/font&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td align="left"&gt;&amp;nbsp;&amp;nbsp;
          &lt;a href="/path_to_file.csv"&gt;&lt;tt&gt;file1.csv&lt;/tt&gt;&lt;/a&gt;&lt;/td&gt;
          &lt;td align="right"&gt;&lt;tt&gt;86.6 kb&lt;/tt&gt;&lt;/td&gt;
          &lt;td align="right"&gt;&lt;tt&gt;Fri, 21 Mar 2014 21:00:19 GMT&lt;/tt&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr bgcolor="#eeeeee"&gt;
          &lt;td align="left"&gt;&amp;nbsp;&amp;nbsp;
          &lt;a href="/path_to_file.csv"&gt;&lt;tt&gt;file2.csv&lt;/tt&gt;&lt;/a&gt;&lt;/td&gt;
          &lt;td align="right"&gt;&lt;tt&gt;20.7 kb&lt;/tt&gt;&lt;/td&gt;
          &lt;td align="right"&gt;&lt;tt&gt;Fri, 21 Mar 2014 21:00:19 GMT&lt;/tt&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td align="left"&gt;&amp;nbsp;&amp;nbsp;
          &lt;a href="/path_to_file.xml"&gt;&lt;tt&gt;file1.xml&lt;/tt&gt;&lt;/a&gt;&lt;/td&gt;
          &lt;td align="right"&gt;&lt;tt&gt;266.5 kb&lt;/tt&gt;&lt;/td&gt;
          &lt;td align="right"&gt;&lt;tt&gt;Fri, 21 Mar 2014 21:00:19 GMT&lt;/tt&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr bgcolor="#eeeeee"&gt;
          &lt;td align="left"&gt;&amp;nbsp;&amp;nbsp;
          &lt;a href="/path_to_file.xml"&gt;&lt;tt&gt;file2.xml&lt;/tt&gt;&lt;/a&gt;&lt;/td&gt;
          &lt;td align="right"&gt;&lt;tt&gt;27.2 kb&lt;/tt&gt;&lt;/td&gt;
          &lt;td align="right"&gt;&lt;tt&gt;Fri, 21 Mar 2014 21:00:19 GMT&lt;/tt&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Answer (thanks @Enragedmrt):</p>
  
  <pre><code>    res.on('data', function(data) {
  
          $ = cheerio.load(data.toString());
          var data = [];
          $('tr').each(function(i, tr){
  
              var children = $(this).children();
              var fileItem = children.eq(0);
              var linkItem = children.eq(0).children().eq(0);
              var lastModifiedItem = children.eq(2);
  
              var row = {
                  "Filename": fileItem.text().trim(),
                  "Link": linkItem.attr("href"),
                  "LastModified": lastModifiedItem.text().trim()
              };
              data.push(row);
              console.log(row);
          });
      });
  </code></pre>