문제

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!

도움이 되었습니까?

해결책

Just use the selector '.clickableRow td'.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top