Readme

cheerio

cheerio is a popular npm module that makes it easy to parse and manipulate HTML and XML.

cheerio is modeled after a reduced version of jQuery. Note that it's pretty different than default browser DOM methods, so you can't call things like .appendChild or document.createElement when using cheerio: it's not based on a full-fledged DOM or browser implementation. But, in exchange it's a lot faster and simpler.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export let cheerioExample = (async () => {
const { default: $ } = await import("npm:cheerio");
const document = $(
`<select name="ctl00$bodyContentPlaceHolder$ddlistPlayDate" onchange="javascript:setTimeout('__doPostBack(\'ctl00$bodyContentPlaceHolder$ddlistPlayDate\',\'\')', 0)" id="ctl00_bodyContentPlaceHolder_ddlistPlayDate" ondatabinding="document.body.style.cu
<option selected="selected" value="606">6/4/2024 8:00:00 PM</option>
<option selected="selected" value="606">6/5/2024 8:00:00 PM</option>
<option selected="selected" value="606">6/6/2024 8:00:00 PM</option>
</select>`,
);
const elements = document.find("#ctl00_bodyContentPlaceHolder_ddlistPlayDate > option");
console.log(elements.map((_, e) => $(e).text()));
// return document.find("#ctl00_bodyContentPlaceHolder_ddlistPlayDate > option").map(e => e.text());
})();
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
June 2, 2024