Cheerio
jQuery-like syntax for parsing and manipulating HTML/XML with server-side speed.
3. Used by agents' projects
Dependency in 76 public GitHub projects set up for AI coding agents that we scanned (1.2%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What Cheerio does
Cheerio gives you jQuery's selector-and-chain API over an HTML or XML string you load yourself, with no browser DOM underneath.
Cheerio popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Cheerio is used
- Cheerio is a dependency in 76 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (1.6% of the 4,867 JavaScript/TypeScript ones), #6 of 141 in scraping, browsers and parsing.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 313; those are left out of every share on this page.
- The most used alternative in our scan is Puppeteer (86 projects).
- Projects that use it most often also use Axios (44.7%), dotenv (47.4%), TypeScript (81.6%).
By coding agent
Often used with
Cheerio in practice
Strengths
The API is a subset of core jQuery. Selectors like <code>$('ul .pear')</code> and methods like <code>.text()</code>, <code>.attr()</code> and <code>.addClass()</code> carry over. The maintainers say they removed the DOM inconsistencies and browser cruft.
Cheerio parses HTML with parse5 by default. The README says it can optionally use htmlparser2, which it calls "forgiving".
The README says it can handle "nearly any" HTML or XML document and works in both environments.
The maintainers say a "very simple, consistent DOM model" makes parsing, manipulating and rendering efficient. A screencast linked from the README claims Cheerio is faster than JSDOM + jQuery. No figures are given.
Watch out for
Cheerio implements only a subset of core jQuery. Do not assume every jQuery method you know is present.
jQuery works on the page's built-in DOM. Cheerio has none, so every document must be passed to <code>cheerio.load()</code> first.
The README examples show that loading a fragment and calling <code>$.html()</code> returns it wrapped in <code><html><head></head><body></code>. For a single element's markup, the README uses <code>.prop('outerHTML')</code> instead.
Load, select, modify, render
import * as cheerio from 'cheerio';
const $ = cheerio.load('<h2 class="title">Hello world</h2>');
$('h2.title').text('Hello there!');
$('h2').addClass('welcome');
$.html();
//=> <html><head></head><body><h2 class="title welcome">Hello there!</h2></body></html>More about Cheerio
Funding
- GitHub Sponsors: https://github.com/cheeriojs
- GitHub Sponsors: https://github.com/fb55
- Open Collective: https://opencollective.com/cheerio
- Own page: https://github.com/cheeriojs/cheerio?sponsor=1
- 4 GitHub sponsors
Packages around it
- axios: HTTP client
- dotenv: Env variables
- zod: Schema validation
- express: Web server
- tailwindcss: Utility CSS
- tsx: Run TypeScript
More in Scraping, browsers and parsing
Alternatives
Cheerio This page
Headless Chrome/Chromium automation for scraping, testing and screenshot generation.
Lightweight DOM implementation using linked lists for Node.js.
Fast, spec-compliant HTML parser and serializer for Node.js and browsers.
XML to JavaScript object parser for handling XML data in applications.
Get started
Install it.
npm install cheerioRules for your agent
## Cheerio
- Import with `import * as cheerio from 'cheerio'` in ESM or TypeScript, and `const cheerio = require('cheerio')` elsewhere.
- Always call `cheerio.load(html)` first. There is no implicit document like jQuery's.
- Query with `$(selector, [context], [root])`. `context` scopes the search, as in `$('.apple', '#fruits')`.
- Only a subset of core jQuery exists. Check the docs before using a jQuery method.
- `$.html()` and `$.root().html()` render a full document with `<html><head><body>` added. Use `$(sel).prop('outerHTML')` for one element's markup.
- Use `.text()` for text content. Rely only on the node properties the README lists: `tagName`, `parentNode`, `previousSibling`, `nextSibling`, `nodeValue`, `firstChild`, `childNodes`, `lastChild`.