EN
FRENCH
繁体中文
Cheerio is a fast and lightweight JavaScript library used to parse and manipulate HTML and XML on the server side.
It is mainly used with Node.js and provides a jQuery-like syntax for navigating document structures, selecting elements, and extracting content. Cheerio is especially useful for web scraping tasks that involve static HTML and do not require a full browser.
Also known as: Cheerio.js, jQuery for the server.
Cheerio and jQuery use similar syntax for selecting and manipulating elements, but they run in different environments.
Cheerio is designed for server-side use with Node.js and focuses on parsing HTML and XML.
jQuery runs in the browser and includes browser-specific features such as event handling, animations, and interaction with the live DOM.
In simple terms:
Cheerio and Puppeteer can both be used in web scraping, but they are suited to different types of websites.
Cheerio works directly with HTML and is lightweight and fast.
Puppeteer controls a real Chromium browser and can execute JavaScript, interact with page elements, and access dynamically rendered content.
For static pages, Cheerio is usually more efficient. For JavaScript-heavy websites, browser automation tools such as Puppeteer are often more appropriate.
Cheerio is commonly used to extract information from static webpages.
A typical workflow includes:
It can be useful for extracting:
Cheerio itself does not send network requests or manage proxies.
In a proxy-based scraping workflow, an HTTP client retrieves the page through a proxy and passes the resulting HTML to Cheerio.
This keeps the responsibilities separate: the proxy handles network routing, the HTTP client downloads the page, and Cheerio parses the content.
The following example uses Cheerio to extract titles and links from static HTML:
const cheerio = require('cheerio');
const html = `
<ul>
<li><a href="/article-1">Article 1</a></li>
<li><a href="/article-2">Article 2</a></li>
</ul>
`;
const $ = cheerio.load(html);
$('a').each((index, element) => {
const title = $(element).text();
const link = $(element).attr('href');
console.log(title, link);
});
Cheerio loads the HTML, selects every <a> element, and extracts both its visible text and href attribute.
Partnership