mardi 1 mars 2016

Cheerio scrapping an Array

I have a problème in a web scrapping project here is a sample of the page i need to scrap

<table style="position...">
   <thead>..</thead>
     <tbody id="leaderboard_body">
       <tr bgcolor="#155555">..</tr>
       <tr bgcolor="#155555">..</tr>
       <tr bgcolor="#155555">..</tr>
                ...
     </tbody>
</table>

for more detail here his the page http://ift.tt/1lWUj4X

and i whant to acced to the information in those tr but i can't archieve it. I can't find the tbody with a simple code like this one and i duno why

var cheerio = require("cheerio");
var url = "http://ift.tt/1ONXp1H";
var http = require("http");

// Utility function that downloads a URL and invokes
// callback with the data.
function download(url, callback) {
  http.get(url, function(res) {
    var data = "";
    res.on('data', function (chunk) {
      data += chunk;
    });
    res.on("end", function() {
      callback(data);
    });
  }).on("error", function() {
    callback(null);
  });
}

download(url, function(data) {
  if (data) {

var $ = cheerio.load(data);
var content = $('tbody').text();
console.log(content);
    }
  else
    console.log(err);
  
});

If someone can help my with that !




Aucun commentaire:

Enregistrer un commentaire