Hacker News new | ask | show | jobs
by rodw 2059 days ago
Self-plug warning but FWIW if you're using cheerio _just_ for the selector syntax a related tool is Stew [1] which is a dependency-free [2] node module that allows one to extract content from web pages (DOM trees) using CSS selectors, like:

var links = stew.select(dom,'a[href]');

extended with support for embeded regular expressions (for tags, classes, IDs, attributes or attribute values). E.g.:

var metadata = stew.select(dom,'head meta[name=/^dc\.|:/i]');

It's on npm as `stew-select`

[1] https://github.com/rodw/stew/

[2] there's an optional peer-dependency-ish relationship to htmlparser or htmlparser2 or similar to generate a DOM tree from raw HTML but anything that creates a basic DOM tree (`{type:, name:, children:[] }`) will suffice