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 graceful…

, '')),\n image: $el.find('img').attr('src'),\n link: $el.find('a').attr('href')\n}));\n```\n\n### Pagination Links\n```javascript\nfunction extractPaginationLinks() {\n return $('.pagination a')\n .map((i, el) => $(el).attr('href'))\n .get()\n .filter(href => href && !href.includes('#'));\n}\n```\n\n## Handling Missing Data\n\n```javascript\n// Safe extraction with defaults\nfunction safeText(selector, defaultValue = '') {\n const el = $(selector);\n return el.length ? el.text().trim() : defaultValue;\n}\n\nfunction safeAttr(selector, attr, defaultValue = null) {\n const el = $(selector);\n return el.length ? el.attr(attr) : defaultValue;\n}\n\n// Optional chaining pattern\nconst price = $('.price').first().text()?.trim() || 'N/A';\n```\n\n## URL Resolution\n\n```javascript\nconst { URL } = require('url');\n\nfunction resolveUrl(baseUrl, relativeUrl) {\n if (!relativeUrl) return null;\n try {\n return new URL(relativeUrl, baseUrl).href;\n } catch {\n return relativeUrl;\n }\n}\n\n// Usage\nconst baseUrl = 'https://example.com/products/';\n$('a').each((i, el) => {\n const href = $(el).attr('href');\n const absoluteUrl = resolveUrl(baseUrl, href);\n console.log(absoluteUrl);\n});\n```\n\n## Performance Optimization\n\n```javascript\n// Cache selections\nconst $products = $('.product');\n$products.each((i, el) => {\n const $product = $(el); // Wrap once\n // Use $product multiple times\n});\n\n// Limit parsing scope\nconst $article = $('.article');\nconst title = $article.find('.title').text(); // Searches only within article\n\n// Use specific selectors\n// Good\n$('div.product > h2.title')\n// Less efficient\n$('div').find('.product').find('h2').filter('.title')\n```\n\n## Complete Scraping Example\n\n```javascript\nconst cheerio = require('cheerio');\nconst axios = require('axios');\n\nasync function scrapeProducts(url) {\n const response = await axios.get(url, {\n headers: {\n 'User-Agent': 'Mozilla/5.0 (compatible; MyScraper/1.0)'\n }\n });\n\n const $ = cheerio.load(response.data);\n const products = [];\n\n $('.product-card').each((index, element) => {\n const $el = $(element);\n\n products.push({\n name: $el.find('.product-title').text().trim(),\n price: parseFloat(\n $el.find('.price').text().replace(/[^0-9.]/g, '')\n ),\n rating: parseFloat($el.find('.rating').attr('data-rating')) || null,\n image: $el.find('img').attr('src'),\n url: new URL($el.find('a').attr('href'), url).href,\n inStock: !$el.find('.out-of-stock').length\n });\n });\n\n return products;\n}\n\n// With error handling\nasync function safeScrape(url) {\n try {\n return await scrapeProducts(url);\n } catch (error) {\n console.error(`Failed to scrape ${url}:`, error.message);\n return [];\n }\n}\n```\n\n## Key Dependencies\n\n- cheerio\n- axios (HTTP client)\n- got (alternative HTTP client)\n- node-fetch (fetch API for Node.js)\n- p-limit (concurrency control)\n\n## Best Practices\n\n1. Always handle missing elements gracefully\n2. Use specific selectors for better performance\n3. Cache jQuery-wrapped elements when reusing\n4. Normalize extracted text (trim whitespace)\n5. Resolve relative URLs to absolute\n6. Validate extracted data types\n7. Implement rate limiting when scraping multiple pages\n8. Use appropriate User-Agent headers\n9. Handle character encoding issues\n10. Log extraction failures for debugging","attachment_filenames":[],"attachments":[],"content_json":{"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"text":"Cheerio HTML Parsing","type":"text"}]},{"type":"paragraph","content":[{"text":"You are an expert in Cheerio, Node.js HTML parsing, DOM manipulation, and building efficient data extraction pipelines for web scraping.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Core Expertise","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Cheerio API and jQuery-like syntax","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"CSS selector optimization","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"DOM traversal and manipulation","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"HTML/XML parsing strategies","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Integration with HTTP clients (axios, got, node-fetch)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Memory-efficient processing of large documents","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Data extraction patterns and best practices","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Key Principles","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Write clean, modular extraction functions","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Use efficient selectors to minimize parsing overhead","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Handle malformed HTML gracefully","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Implement proper error handling for missing elements","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Design reusable scraping utilities","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Follow functional programming patterns where appropriate","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Basic Setup","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"npm install cheerio axios","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Loading HTML","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"const cheerio = require('cheerio');\nconst axios = require('axios');\n\n// Load from string\nconst $ = cheerio.load('\u003chtml>\u003cbody>\u003ch1>Hello\u003c/h1>\u003c/body>\u003c/html>');\n\n// Load with options\nconst $ = cheerio.load(html, {\n xmlMode: false, // Parse as XML\n decodeEntities: true, // Decode HTML entities\n lowerCaseTags: false, // Keep tag case\n lowerCaseAttributeNames: false\n});\n\n// Fetch and parse\nasync function fetchAndParse(url) {\n const response = await axios.get(url);\n return cheerio.load(response.data);\n}","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Selecting Elements","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"CSS Selectors","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"// By tag\n$('h1')\n\n// By class\n$('.article')\n\n// By ID\n$('#main-content')\n\n// By attribute\n$('[data-id=\"123\"]')\n$('a[href^=\"https://\"]') // Starts with\n$('a[href$=\".pdf\"]') // Ends with\n$('a[href*=\"example\"]') // Contains\n\n// Combinations\n$('div.article > h2') // Direct child\n$('div.article h2') // Any descendant\n$('h2 + p') // Adjacent sibling\n$('h2 ~ p') // General sibling\n\n// Pseudo-selectors\n$('li:first-child')\n$('li:last-child')\n$('li:nth-child(2)')\n$('li:nth-child(odd)')\n$('tr:even')\n$('input:not([type=\"hidden\"])')\n$('p:contains(\"specific text\")')","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Multiple Selectors","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"// Select multiple types\n$('h1, h2, h3')\n\n// Chain selections\n$('.article').find('.title')","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Extracting Data","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Text Content","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"// Get text (includes child text)\nconst text = $('h1').text();\n\n// Get trimmed text\nconst text = $('h1').text().trim();\n\n// Get HTML\nconst html = $('div.content').html();\n\n// Get outer HTML\nconst outerHtml = $.html($('div.content'));","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Attributes","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"// Get attribute\nconst href = $('a').attr('href');\nconst src = $('img').attr('src');\n\n// Get data attributes\nconst id = $('div').data('id'); // data-id attribute\n\n// Check if attribute exists\nconst hasClass = $('div').hasClass('active');","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Multiple Elements","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"// Iterate with each\nconst items = [];\n$('.product').each((index, element) => {\n items.push({\n name: $(element).find('.name').text().trim(),\n price: $(element).find('.price').text().trim(),\n url: $(element).find('a').attr('href')\n });\n});\n\n// Map to array\nconst titles = $('h2').map((i, el) => $(el).text()).get();\n\n// Filter elements\nconst featured = $('.product').filter('.featured');\n\n// First/Last\nconst first = $('li').first();\nconst last = $('li').last();\n\n// Get by index\nconst third = $('li').eq(2);","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"DOM Traversal","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Navigation","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"// Parent\n$('span').parent()\n$('span').parents() // All ancestors\n$('span').parents('.container') // Specific ancestor\n$('span').closest('.wrapper') // Nearest ancestor matching selector\n\n// Children\n$('ul').children() // Direct children\n$('ul').children('li.active') // Filtered children\n$('div').contents() // Including text nodes\n\n// Siblings\n$('li').siblings()\n$('li').next()\n$('li').nextAll()\n$('li').prev()\n$('li').prevAll()","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Filtering","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"// Filter by selector\n$('li').filter('.active')\n\n// Filter by function\n$('li').filter((i, el) => $(el).data('price') > 100)\n\n// Find within selection\n$('.article').find('img')\n\n// Check conditions\n$('li').is('.active') // Returns boolean\n$('li').has('span') // Has descendant matching selector","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Data Extraction Patterns","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Table Extraction","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"function extractTable(tableSelector) {\n const $ = this;\n const headers = [];\n const rows = [];\n\n // Get headers\n $(tableSelector).find('th').each((i, el) => {\n headers.push($(el).text().trim());\n });\n\n // Get rows\n $(tableSelector).find('tbody tr').each((i, row) => {\n const rowData = {};\n $(row).find('td').each((j, cell) => {\n rowData[headers[j]] = $(cell).text().trim();\n });\n rows.push(rowData);\n });\n\n return rows;\n}","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"List Extraction","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"function extractList(selector, itemExtractor) {\n return $(selector).map((i, el) => itemExtractor($(el))).get();\n}\n\n// Usage\nconst products = extractList('.product', ($el) => ({\n name: $el.find('.name').text().trim(),\n price: parseFloat($el.find('.price').text().replace('

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 graceful…

, '')),\n image: $el.find('img').attr('src'),\n link: $el.find('a').attr('href')\n}));","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Pagination Links","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"function extractPaginationLinks() {\n return $('.pagination a')\n .map((i, el) => $(el).attr('href'))\n .get()\n .filter(href => href && !href.includes('#'));\n}","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Handling Missing Data","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"// Safe extraction with defaults\nfunction safeText(selector, defaultValue = '') {\n const el = $(selector);\n return el.length ? el.text().trim() : defaultValue;\n}\n\nfunction safeAttr(selector, attr, defaultValue = null) {\n const el = $(selector);\n return el.length ? el.attr(attr) : defaultValue;\n}\n\n// Optional chaining pattern\nconst price = $('.price').first().text()?.trim() || 'N/A';","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"URL Resolution","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"const { URL } = require('url');\n\nfunction resolveUrl(baseUrl, relativeUrl) {\n if (!relativeUrl) return null;\n try {\n return new URL(relativeUrl, baseUrl).href;\n } catch {\n return relativeUrl;\n }\n}\n\n// Usage\nconst baseUrl = 'https://example.com/products/';\n$('a').each((i, el) => {\n const href = $(el).attr('href');\n const absoluteUrl = resolveUrl(baseUrl, href);\n console.log(absoluteUrl);\n});","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Performance Optimization","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"// Cache selections\nconst $products = $('.product');\n$products.each((i, el) => {\n const $product = $(el); // Wrap once\n // Use $product multiple times\n});\n\n// Limit parsing scope\nconst $article = $('.article');\nconst title = $article.find('.title').text(); // Searches only within article\n\n// Use specific selectors\n// Good\n$('div.product > h2.title')\n// Less efficient\n$('div').find('.product').find('h2').filter('.title')","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Complete Scraping Example","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"javascript"},"content":[{"text":"const cheerio = require('cheerio');\nconst axios = require('axios');\n\nasync function scrapeProducts(url) {\n const response = await axios.get(url, {\n headers: {\n 'User-Agent': 'Mozilla/5.0 (compatible; MyScraper/1.0)'\n }\n });\n\n const $ = cheerio.load(response.data);\n const products = [];\n\n $('.product-card').each((index, element) => {\n const $el = $(element);\n\n products.push({\n name: $el.find('.product-title').text().trim(),\n price: parseFloat(\n $el.find('.price').text().replace(/[^0-9.]/g, '')\n ),\n rating: parseFloat($el.find('.rating').attr('data-rating')) || null,\n image: $el.find('img').attr('src'),\n url: new URL($el.find('a').attr('href'), url).href,\n inStock: !$el.find('.out-of-stock').length\n });\n });\n\n return products;\n}\n\n// With error handling\nasync function safeScrape(url) {\n try {\n return await scrapeProducts(url);\n } catch (error) {\n console.error(`Failed to scrape ${url}:`, error.message);\n return [];\n }\n}","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Key Dependencies","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"cheerio","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"axios (HTTP client)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"got (alternative HTTP client)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"node-fetch (fetch API for Node.js)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"p-limit (concurrency control)","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Best Practices","type":"text"}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Always handle missing elements gracefully","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Use specific selectors for better performance","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Cache jQuery-wrapped elements when reusing","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Normalize extracted text (trim whitespace)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Resolve relative URLs to absolute","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Validate extracted data types","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Implement rate limiting when scraping multiple pages","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Use appropriate User-Agent headers","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Handle character encoding issues","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Log extraction failures for debugging","type":"text"}]}]}]}]},"metadata":{"date":"2026-11-02","name":"cheerio-parsing","author":"@skillopedia","source":{"stars":291,"repo_name":"skills","origin_url":"https://github.com/Mindrally/skills/blob/HEAD/cheerio-parsing/SKILL.md","repo_owner":"Mindrally","body_sha256":"5384c275fab53295ab43f8c2f0b73582d58024f7de8865e2f8d3a72d03681a35","cluster_key":"3c7714ac63ed264913a8186268501d1e873cbfb984c5f89dedcdfa2f3f63fb41","clean_bundle":{"format":"clean-skill-bundle-v1","source":"Mindrally/skills/cheerio-parsing/SKILL.md","text_bytes":0,"source_commit":"7682ca77710e0971eab4e0ae5dddfa281aea0ba5","skills_sh_rank":14438,"attachment_count":0,"text_attachments":0,"attachment_storage":"skill_attachments","binary_attachments":0},"cluster_size":1,"skill_md_path":"cheerio-parsing/SKILL.md","import_metadata":{"date":"2026-11-02","author":"@skillopedia","version":"v1","category":"browser-automation-scraping","category_label":"Browser"},"exact_dupes_collapsed_into_this":0},"version":"v1","category":"browser-automation-scraping","metadata":{"source":"https://github.com/Mindrally/skills","maintainer":"Mindrally"},"import_tag":"skills-sh-top20k-2026-11","description":"Expert guidance for HTML/XML parsing using Cheerio in Node.js with best practices for DOM traversal, data extraction, and efficient scraping pipelines."}},"renderedAt":1793671773454}

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 graceful…