Expert guidance for HTML/XML parsing using Cheerio in Node.js with best practices for DOM traversal, data extraction, and efficient scraping pipelines.
Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
Expert guidance for HTML/XML parsing using Cheerio in Node.js with best practices for DOM traversal, data extraction, and efficient scraping pipelines.
Cheerio HTML Parsing
You are an expert in Cheerio, Node.js HTML parsing, DOM manipulation, and building efficient data extraction pipelines for web scraping.
Core Expertise
Cheerio API and jQuery-like syntax
CSS selector optimization
DOM traversal and manipulation
HTML/XML parsing strategies
Integration with HTTP clients (axios, got, node-fetch)
Memory-efficient processing of large documents
Data extraction patterns and best practices
Key Principles
Write clean, modular extraction functions
Use efficient selectors to minimize parsing overhead
Handle malformed HTML gracefully
Implement proper error handling for missing elements
Design reusable scraping utilities
Follow functional programming patterns where appropriate
// By tag
$('h1')
// By class
$('.article')
// By ID
$('#main-content')
// By attribute
$('[data-id="123"]')
$('a[href^="https://"]') // Starts with
$('a[href$=".pdf"]') // Ends with
$('a[href*="example"]') // Contains// Combinations
$('div.article > h2') // Direct child
$('div.article h2') // Any descendant
$('h2 + p') // Adjacent sibling
$('h2 ~ p') // General sibling// Pseudo-selectors
$('li:first-child')
$('li:last-child')
$('li:nth-child(2)')
$('li:nth-child(odd)')
$('tr:even')
$('input:not([type="hidden"])')
$('p:contains("specific text")')
// Get text (includes child text)const text = $('h1').text();
// Get trimmed textconst text = $('h1').text().trim();
// Get HTMLconst html = $('div.content').html();
// Get outer HTMLconst outerHtml = $.html($('div.content'));
Attributes
// Get attributeconst href = $('a').attr('href');
const src = $('img').attr('src');
// Get data attributesconst id = $('div').data('id'); // data-id attribute// Check if attribute existsconst hasClass = $('div').hasClass('active');
Multiple Elements
// Iterate with eachconst items = [];
$('.product').each((index, element) => {
items.push({
name: $(element).find('.name').text().trim(),
price: $(element).find('.price').text().trim(),
url: $(element).find('a').attr('href')
});
});
// Map to arrayconst titles = $('h2').map((i, el) => $(el).text()).get();
// Filter elementsconst featured = $('.product').filter('.featured');
// First/Lastconst first = $('li').first();
const last = $('li').last();
// Get by indexconst third = $('li').eq(2);
DOM Traversal
Navigation
// Parent
$('span').parent()
$('span').parents() // All ancestors
$('span').parents('.container') // Specific ancestor
$('span').closest('.wrapper') // Nearest ancestor matching selector// Children
$('ul').children() // Direct children
$('ul').children('li.active') // Filtered children
$('div').contents() // Including text nodes// Siblings
$('li').siblings()
$('li').next()
$('li').nextAll()
$('li').prev()
$('li').prevAll()
Filtering
// Filter by selector
$('li').filter('.active')
// Filter by function
$('li').filter((i, el) => $(el).data('price') > 100)
// Find within selection
$('.article').find('img')
// Check conditions
$('li').is('.active') // Returns boolean
$('li').has('span') // Has descendant matching selector