Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import cheerio module to TypeScript app

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
...
like image 240
Edgaras Karka Avatar asked Nov 06 '17 19:11

Edgaras Karka


People also ask

How do you import Cheerios?

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.

Does Cheerio use jQuery?

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.

How do you use Cheerio in HTML?

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.


2 Answers

It works for me import * as cheerio from 'cheerio';

like image 199
Edgaras Karka Avatar answered Oct 16 '22 21:10

Edgaras Karka


it's exported as defalut. try

import cheerio from 'cheerio'

like image 25
Rafi Henig Avatar answered Oct 16 '22 22:10

Rafi Henig