Cheerio loads HTML or XML and exposes a familiar selector API to traverse and change documents. It is used heavily for server-side parsing and scraping tasks.
Overview
Cheerio is a JavaScript library for parsing and working with HTML and XML outside the browser. It implements a subset of the jQuery API on top of a simple DOM model so you can load markup, query with CSS selectors, read and mutate elements, and render serialized HTML or text.
Parsing can go through parse5 for HTML or optionally the more forgiving htmlparser2, which helps with imperfect documents. Collections behave like lightweight DOM nodes with properties such as tagName, parentNode, and childNodes, and methods mirror common jQuery patterns for finding and updating content.
Because it avoids full browser machinery, Cheerio is oriented toward efficient parse-and-transform workflows in Node and similar environments. The project notes use in production for HTML transformation scripts and scraping pipelines, and documents that it runs in both browser and server contexts.
Installation is via standard JavaScript package managers. The API centers on loading a document string, selecting elements, manipulating them, and exporting html, outerHTML, or text results from the root selection.
Key features
- jQuery-like selector syntax
- HTML and XML parsing
- parse5 and htmlparser2 backends
- DOM traversal and manipulation
- HTML and text rendering
- Server and browser use
- Lightweight DOM model
- npm package distribution
Use cases
- Server-side HTML transforms
- Scraping static page markup
- Templating and post-processing HTML
- Extracting text from documents