user3473406
user3473406

Reputation: 155

Selecting a span within a certain table Cheerio

I am parsing a website and have multiple tables that look something like this.

<table class="first tableWithData">
<tbody>
<tr class="first rowTable">
<td class="infoAvail">
    <span class="linking">Saturday</span>
</td>
</tr>
</tbody>
</table>

The table class name being unique for each table.

I want to pull out the span class of Linking for each row in this particular table but I am struggling on what DOM selection to use.

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

request('http://testWebsite.com', function (error, response, html) {
  if (!error && response.statusCode == 200) {
    var $ = cheerio.load(html);
    $('table.first tableWithData td span.linking').each(function(i, element)
{
      var a = $(this);
      console.log(a.text());
    });
  }
});

Upvotes: 0

Views: 817

Answers (1)

hsz
hsz

Reputation: 152286

You have a dot missing:

table.first.tableWithData td span.linking
//         ^

Upvotes: 1

Related Questions