cheerio
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "cheerio":https://skillpi.com/zh/skills/deepskill-74a5f5fc73527192cd989bb83fdbec60c2c95efbac617fc6a3de18e2e9540f6d。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
Cheerio HTML 解析:用于解析和提取 HTML 数据,适合抓取静态网页、解析 HTML 文件、为服务端渲染构建爬虫、从文档提取文本或链接、解析 RSS/XML、转换 HTML 内容或处理 HTML 邮件。提供 jQuery 风格选择器、DOM 遍历、文本与属性提取,并可与 HTTP 客户端集成构建爬虫流水线。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 实测状态
- 未测试
文件浏览
Frontmatter
name: cheerio
description: >-
Parse and extract data from HTML with Cheerio. Use when a user asks to scrape
static web pages, parse HTML files, extract data from HTML, build a web
scraper for server-rendered pages, extract text or links from HTML documents,
parse RSS/XML feeds, transform HTML content, or process HTML emails. Covers
jQuery-style selectors, DOM traversal, text extraction, attribute parsing,
and integration with HTTP clients for web scraping pipelines.
license: Apache-2.0
compatibility: 'Node.js 14+ (any platform)'
metadata:
author: terminal-skills
version: 1.0.0
category: development
tags:
- cheerio
- html
- parsing
- scraping
- dom
- extractCheerio
Overview
Cheerio is a fast, lightweight HTML/XML parser for Node.js that implements a jQuery-like API. Unlike Puppeteer, it does not run a browser — it parses raw HTML strings, making it 100x faster and ideal for scraping server-rendered pages, parsing HTML files, and transforming HTML content. Pair it with fetch or axios for web scraping, or use it standalone for HTML processing.
Instructions
Step 1: Installation
npm install cheerio
Step 2: Parse HTML and Extract Data
// parse_html.js — Load HTML and extract structured data with CSS selectors
import * as cheerio from 'cheerio'
const html = `
<html>
<body>
<h1>Products</h1>
<div class="product" data-id="1">
<h2>Widget Pro</h2>
<span class="price">$29.99</span>
<a href="/products/widget-pro">Details</a>
</div>
<div class="product" data-id="2">
<h2>Gadget Max</h2>
<span class="price">$49.99</span>
<a href="/products/gadget-max">Details</a>
</div>
</body>
</html>`
const $ = cheerio.load(html)
// Extract all products
const products = []
$('.product').each((i, el) => {
products.push({
id: $(el).attr('data-id'),
title: $(el).find('h2').text().trim(),
price: $(el).find('.price').text().trim(),
link: $(el).find('a').attr('href'),
})
})
console.log(products)
// [{ id: '1', title: 'Widget Pro', price: '$29.99', link: '/products/widget-pro' }, ...]
Step 3: Web Scraping with Fetch
// scrape_site.js — Fetch a page and extract data
import * as cheerio from 'cheerio'
async function scrape(url) {
const response = await fetch(url)
const html = await response.text()
const $ = cheerio.load(html)
// Extract all links
const links = []
$('a[href]').each((i, el) => {
links.push({
text: $(el).text().trim(),
href: $(el).attr('href'),
})
})
// Extract meta tags
const meta = {
title: $('title').text(),
description: $('meta[name="description"]').attr('content'),
ogImage: $('meta[property="og:image"]').attr('content'),
}
return { links, meta }
}
Step 4: Advanced Selectors and Traversal
// selectors.js — Complex CSS selectors and DOM traversal
const $ = cheerio.load(html)
// Attribute selectors
$('a[href^="https"]') // links starting with https
$('img[src$=".png"]') // PNG images
$('div[class*="product"]') // divs with "product" in class
// Traversal
$('.product').first() // first product
$('.product').last() // last product
$('.product').eq(2) // third product (0-indexed)
$('.price').parent() // parent of each .price element
$('.product').children('h2') // direct h2 children
$('.product').find('.price') // descendants matching .price
$('.product').next() // next sibling
$('.product').prev() // previous sibling
// Filtering
$('.product').filter((i, el) => {
const price = parseFloat($(el).find('.price').text().replace('$', ''))
return price < 50
})
// Text and HTML
$('.product').first().text() // all text content, flattened
$('.product').first().html() // inner HTML
Step 5: Table Extraction
// extract_table.js — Parse HTML tables into structured data
function extractTable($, tableSelector) {
/**
* Convert an HTML table to an array of objects using headers as keys.
* Args:
* $: Cheerio instance
* tableSelector: CSS selector for the table element
*/
const headers = []
$(`${tableSelector} thead th`).each((i, el) => {
headers.push($(el).text().trim())
})
const rows = []
$(`${tableSelector} tbody tr`).each((i, tr) => {
const row = {}
$(tr).find('td').each((j, td) => {
row[headers[j]] = $(td).text().trim()
})
rows.push(row)
})
return rows
}
// Usage
const tableData = extractTable($, '#pricing-table')
// [{ Plan: 'Free', Price: '$0', Users: '1' }, { Plan: 'Pro', Price: '$29', Users: '10' }]
Step 6: HTML Transformation
// transform.js — Modify HTML content
const $ = cheerio.load(html)
// Add class
$('.product').addClass('featured')
// Remove elements
$('.ad-banner').remove()
// Replace content
$('h1').text('Updated Title')
// Wrap elements
$('.product').wrap('<section class="product-section"></section>')
// Add attributes
$('a').attr('target', '_blank')
$('img').attr('loading', 'lazy')
// Get modified HTML
const modifiedHtml = $.html()
Examples
Example 1: Build a price monitoring scraper
User prompt: "Scrape product prices from 5 competitor websites daily and save to a CSV. The sites are server-rendered (no JavaScript needed)."
The agent will:
- Use
fetch+ cheerio for each site (no browser overhead). - Write site-specific selectors for product name, price, and availability.
- Parse prices into numbers, normalize currency.
- Append results to a CSV with timestamps.
- Set up as a cron job for daily execution.
Example 2: Extract and clean article content from HTML
User prompt: "I have 1,000 saved HTML pages from a blog. Extract just the article title, author, date, and body text from each, ignoring navigation, ads, and footers."
The agent will:
- Read each HTML file, load with cheerio.
- Extract content using article-specific selectors (
article,.post-content, etc.). - Strip HTML tags from body, normalize whitespace.
- Output structured JSON with title, author, date, and clean text.
Guidelines
- Use cheerio for server-rendered pages (where the HTML contains the data you need). For SPAs or JavaScript-rendered content, use Puppeteer instead.
- Cheerio does not execute JavaScript, fetch external resources, or render CSS — it only parses the HTML string you give it.
- Always call
.trim()on extracted text — HTML often contains whitespace, newlines, and indentation that clutters results. - Use
.attr('href')and.attr('src')to get link/image URLs. Remember these may be relative — resolve them against the base URL. - For large-scale scraping, cheerio is 100x faster than Puppeteer and uses negligible memory. It can process thousands of pages per second.
- Combine cheerio with
fetchoraxiosfor scraping, and add delays between requests to avoid overwhelming target servers.
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供完整的 HTML 解析与数据提取解决方案,覆盖爬虫、内容转换、表格处理等高频开发场景
- 包含端到端示例(价格监控爬虫、文章内容提取),显著提升开发效率
亮点
- 触发词精准覆盖静态网页抓取、HTML 解析、数据提取、爬虫构建等核心场景
- 边界清晰,明确区分 cheerio(服务端渲染)与 Puppeteer(SPA)的适用场景
待提升项
-
description写错位置 原报告严重程度:轻微
顶层 frontmatter 中 description 字段为空,实际描述内容位于 skill_body 内部
改进建议:将 description 内容移至顶层 frontmatter 的 description 字段,保持规范一致性
亮点
- 文档结构完整,包含清晰的步骤划分(6 个步骤)和端到端示例
- frontmatter 完整,兼容性说明明确(Node.js 14+)
亮点
- 提供完整可运行的代码示例,涵盖主要异常处理(trim()、相对 URL 处理)
- 工具来源明确(npm install cheerio),与 HTTP 客户端集成方案清晰
- 包含性能优化建议(100x 快于 Puppeteer)和道德爬取提醒(添加请求延迟)
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 36 行
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。