Cheerio Selectors Example

Extracting HTML with Cheerio Selectors.

Have HTML:



Extracting HTML:

var cheerio= require('cheerio');

var content= "...";
var $= cheerio.load(content);

var data= [];
$('.post-item').each(function(){
    data.push({
        title: $(this).find('h2').text().trim(),
        image: $(this).find('img').attr('src'),
        link: $(this).find('a').eq(0).attr('href')
    });
})

Comments