Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
cheerio-select
Advanced tools
The cheerio-select npm package is a library that allows users to use CSS selectors to select and manipulate HTML elements within a cheerio instance. It is designed to work with the cheerio library, which is a fast, flexible, and lean implementation of core jQuery designed specifically for the server.
Selecting elements
This feature allows you to select HTML elements using CSS selectors. In the code sample, we select elements with the class 'apple' and log their text content.
const cheerio = require('cheerio');
const select = require('cheerio-select');
const html = '<ul id="fruits"><li class="apple">Apple</li><li class="orange">Orange</li></ul>';
const $ = cheerio.load(html);
const elements = select('.apple', $);
console.log($(elements).text()); // 'Apple'
Filtering elements
This feature allows you to filter a set of elements down to those that match a CSS selector. In the code sample, we filter a list of 'li' elements to only those with the class 'apple'.
const cheerio = require('cheerio');
const select = require('cheerio-select');
const html = '<ul id="fruits"><li class="apple">Apple</li><li class="orange">Orange</li></ul>';
const $ = cheerio.load(html);
const fruits = $('li').toArray();
const apples = select.filter('.apple', fruits, $);
console.log($(apples).text()); // 'Apple'
jsdom is a pure-JavaScript implementation of many web standards, notably the WHATWG DOM and HTML Standards, for use with Node.js. It is more comprehensive than cheerio-select as it simulates a web browser's environment, allowing for dynamic content execution, but it is also heavier and slower.
Although jQuery is primarily used in the browser, it can be used in Node.js with a window provided by a package like jsdom. jQuery offers a wide range of features for DOM manipulation and traversal, similar to cheerio-select, but it is not as optimized for server-side usage.
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. It is typically used for browser automation, testing, and scraping. Unlike cheerio-select, Puppeteer operates on a full browser and is capable of rendering JavaScript, making it more powerful but also more resource-intensive.
CSS selector engine supporting jQuery selectors, based on css-select
.
Supports all jQuery positional pseudo-selectors:
:first
:last
:eq
:nth
:gt
:lt
:even
:odd
:not(:positional)
, where :positional
is any of the above.This library is a thin wrapper around css-select
.
Only use this module if you will actually use jQuery positional selectors.
FAQs
CSS selector engine supporting jQuery selectors
We found that cheerio-select demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.