7

I'm trying to parse an HTML table using Node.js and Cheerio and am getting some results but unfortunately I'm getting way too much data and am not sure how to parse it down further to get only the data I need.

Here is the small bit of code I've got going so far..

var request = require("request");
var cheerio = require("cheerio");

request('http://www.myURL.com', function(error, response, body) {

  var $ = cheerio.load(body);

  $('td').each(function() {
    console.log($(this).text());

  });
});

Using a Chrome plugin to locate the selector, I've found that I need ".clickableRow td" but every way I've tried to plug this in doesn't seem to work.

For a little more clarity, the html source looks like this -

<html>
 <body>
  <form>
   <table>
    <tbody>
     <td>
      <table class="standardTable">
       <tbody>
        <tr class="clickableRow">
         <td>first thing I want</td>
         <td>second thing I want</td>
         <td>third thing I want</td>
         <td>fourth thing I want</td>

Does that make sense? The items I want are pretty deep into the HTML and I'm not sure how to get down to that level. Any help would be greatly appreciated! Thanks!

1
  • This question should have more votes, it's well-formatted, clear and provides all relevant information to answer neatly. Commented Feb 7, 2014 at 3:58

1 Answer 1

7

Just use the selector '.clickableRow td'.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep! Thanks! I thought it would be simple like that but I just am not familiar with the syntax here. That listed out exactly what I need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.