Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Node.js and Cheerio parsing table with selectors

Node.js and Cheerio parsing table with selectors

Problem

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 -


 
  

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!

Problem courtesy of: Christian

Solution

Just use the selector '.clickableRow td'.

Solution courtesy of: Peter Lyons

Discussion

View additional discussion.

first thing I want second thing I want third thing I want fourth thing I want


This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Node.js and Cheerio parsing table with selectors

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×