Fast, flexible & lean implementation of core jQuery designed specifically for the server.
Installation
npm install cheerio
Usage
const cheerio = require('cheerio')
const $ = cheerio.load('<h2 class="title">Hello world</h2>')
$('h2.title').text('Hello there!')
$('h2').addClass('welcome')
$.html()
//=> <h2 class="title welcome">Hello there!</h2>
Usage with axios
const cheerio = require('cheerio')
const axios = require('axios')
axios.get( 'https://wintercroft.com/' )
.then( function ( response ) {
var $ = cheerio.load( response.data );
title = $( ' h1' ).first().text().trim();
return title;
} ).then( function (title) {
console.log(title)
});