I try to import cheerio
to my typescript
based app.
import {cheerio} from 'cheerio';
console.log(cheerio); //undefined
from package.json:
...
"@types/cheerio": "^0.22.5
...
Cheerio title In the first example, we get the title of the document. import fetch from 'node-fetch'; import { load } from 'cheerio'; const url = 'http://webcode.me'; const response = await fetch(url); const body = await response. text(); let $ = load(body); let title = $('title'); console. log(title.
Cheerio is a server-side implementation of jQuery. The Crawler uses it to expose the page's DOM so you can extract the content you want using Cheerio's Selectors API.
Loading an HTML String ts to begin. import cheerio from "cheerio"; const $ = cheerio. load('<div><h2 class="primary">First Header</h2><h2>Second Header</h2></div>'); As you can see, all you need to do is pass an HTML string into Cheerio's load method.
It works for me import * as cheerio from 'cheerio';
it's exported as defalut. try
import cheerio from 'cheerio'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With