Reputation: 931
I'm writing a scraper to obtain psp iso files to download based on the rating. I'm having a difficult time targeting each rating. How can I grab this element? I've included a snapshot for reference. The rating element is within a tr td
tag.
var request = require('request'),
cheerio = require('cheerio'),
fs = require('fs');
var url = 'http://goo.gl/cc4HRc',
pspGames = [];
request(url, function (error, response, html) {
if (!error && response.statusCode === 200) {
var $ = cheerio.load(html);
$('.gamelist', 'td').each(function () {
var links = $(this).attr('href');
pspGames.push(links);
});
}
});
Upvotes: 0
Views: 769
Reputation: 3823
I'm not sure how you were going to store the rating, but maybe something like this will help:
$('.gamelist').each(function () {
var link = $(this.attr('href'));
var rating = $(this).parent().siblings().first().text();
pspGames.push({"link": link, "rating": rating});
});
Upvotes: 1
Reputation: 6346
Looking at the link, it looks like this:
<tr>
<td>
<a class="index gamelist" title="Corpse Party - Book of Shadows (Japan) ISO Info and Download" href="/Sony_Playstation_Portable_ISOs/Corpse_Party_-_Book_of_Shadows_(Japan)/158702">Corpse Party - Book of Shadows (Japan)</a>
</td>
<td align="center">4.9504</td>
</tr>
You should just do: $('.gamelist').each(
Upvotes: 1