Cheerio parses and manipulates HTML and XML in JavaScript using a jQuery-like selector API. It runs in server and browser environments and can render documents via html, outerHTML, and text helpers.
Overview
Cheerio is a library for developers who need to load HTML or XML, query elements with CSS-style selectors, traverse the resulting structure, and serialize output without a full browser DOM. It deliberately implements a subset of jQuery core, adapted for environments where only a string document is available at load time.
Parsing can go through parse5 for HTML and optionally use htmlparser2 for forgiving parsing, which allows handling a wide range of markup. The selector entry point mirrors jQuery patterns: you pass markup, then search within a context and root scope to build a collection for further manipulation.
Collections expose DOM-like node properties such as tagName, parent and sibling links, and child node lists, which makes transformations and scraping scripts straightforward to write. Rendering methods produce full document HTML, outer HTML for selections, or text content as needed.
Install is via common JavaScript package managers. Documentation on the project site positions the library for HTML transformation and scraping workflows in Node.js scripts, alongside use in the browser.
Key features
- jQuery-style selectors on loaded markup
- HTML parsing via parse5 with optional htmlparser2
- html, outerHTML, and text rendering
- DOM-like node properties on collections
- Server and browser runtime support
- Traversal and manipulation API
Use cases
- Parsing and transforming HTML in Node.js scripts
- Extracting data from HTML documents with selectors
- Server-side HTML manipulation without a browser
- Building scraping utilities in JavaScript