Skip to content

cheeriovsparse5

MIT 40 13 30,265
80.4 million (month) Oct 08 2011 1.2.0(2026-02-21 19:30:40 ago)
3,886 7 34 MIT
Jul 03 2013 419.4 million (month) 8.0.0(2026-02-21 19:30:52 ago)

cheerio is a popular JavaScript library that allows you to interact with and manipulate HTML and XML documents in a similar way to how you would with jQuery in a browser. It is a fast, flexible, and lean implementation of core jQuery designed specifically for the server.

One of the main benefits of using cheerio is that it allows you to use jQuery-like syntax to navigate and m anipulate the Document Object Model (DOM) of an HTML or XML document, making it easy to work with.

cheerio supports CSS selectors though not XPath.

parse5 is a Node.js library for parsing and manipulating HTML and XML documents. It is designed to be fast and flexible, and it is commonly used in web scraping and web development projects.

parse5 is used by popular libraries such as Angular, Lit, Cheerio and many more. Unlike Cheerio parse5 is a low level html parsing library that might be useful directly in web scraping without higher level abstraction.

Example Use


```javascript const cheerio = require('cheerio'); const $ = cheerio.load('My title

Hello World!

'); // use css selectors console.log($('title').text()); // My title console.log($('.name').text()); // Hello World! // select multiple elements const $ = cheerio.load('
  • item 1
  • item 2
'); $('li').each(function(i, elem) { console.log($(this).text()); }); // modify elements const $ = cheerio.load('

Hello World!

'); $('h1').text('Hello, Cheerio!'); console.log($.html()); ```
```javascript const parse5 = require("parse5"); // parse string const document = parse5.parse('Hello World!'); console.log(document); // html tree can be traversed as javascript object: const body = document.childNodes[1]; console.log(body.childNodes[0].value); // "Hello World!" // and modified const newElement = parse5.parseFragment('

New Element

'); body.appendChild(newElement.childNodes[0]); console.log(parse5.serialize(document)); ```

Alternatives / Similar


Was this page helpful?