Deno Cheerio
Cheerio - Porting Cheerio Node Module To Deno using esm.sh
Prerequisites
- Deno on your System https://deno.land/#installation
Usage
- Cheerio Full Docs and usage - https://cheerio.js.org/
import { cheerio } from "https://deno.land/x/denocheerio/mod.ts";
fetch(
"https://notes.santhoshveer.com/",
)
.then((result) => result.text())
.then((html) => {
const $ = cheerio.load(html);
const title = $('meta[property="og:title"]').attr("content") ||
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mi mathvariant="normal">"</mi><mi>t</mi><mi>i</mi><mi>t</mi><mi>l</mi><mi>e</mi><mi mathvariant="normal">"</mi><mo stretchy="false">)</mo><mi mathvariant="normal">.</mi><mi>t</mi><mi>e</mi><mi>x</mi><mi>t</mi><mo stretchy="false">(</mo><mo stretchy="false">)</mo><mi mathvariant="normal">∣</mi><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">("title").text() || </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord">"</span><span class="mord mathnormal">t</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.01968em;">tl</span><span class="mord mathnormal">e</span><span class="mord">"</span><span class="mclose">)</span><span class="mord">.</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mord mathnormal">t</span><span class="mopen">(</span><span class="mclose">)</span><span class="mord">∣∣</span></span></span></span>('meta[name="title"]').attr("content");
const description = $('meta[property="og:description"]').attr("content") ||
$('meta[name="description"]').attr("content");
console.log(title);
console.log(description);
}).catch((error) => {
console.log(error);
});
Testing
deno run --allow-net --allow-read test.ts
or
deno task test
Credits
- cheerio Npm Module - https://github.com/cheeriojs/cheerio
LICENSE
MIT