Search code examples
jquerynode.jsweb-scrapingscreen-scrapingcheerio

Scraping with Cheerio


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);
    });
   }
});

enter image description here


Solution

  • 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(