• 카테고리

    질문 & 답변
  • 세부 분야

    데이터 분석

  • 해결 여부

    미해결

cheerio deprecated

22.11.07 10:32 작성 조회수 672

0

const crawler = async() => {
    await Promise.all(records.map( async(r) => {
        const response = await axios.get(r.링크)
        if(response.status === 200){
            const html = response.data
            const $ = cheerio.load(html)
            const text = $('.score.score_left .star_score').text()
            console.log(r.제목,'평점',text)
        }
    } ))
}

1-4 axios-cheerio로 첫 크롤링하기 강의중
const $ = cheerio.load시 cheerio에 빗금이 처지며 deprecated라는 표시가 뜹니다. 무시하고 그냥 해도 결과는 나오지만 구글링을 해봐도 deprecated대신 사용할수있는게 없어 그냥 해야하나 아니면 다른 방법으로 대체해야하나 궁금합니다.

package.json은 아래와 같습니다.

"dependencies": {
    "axios": "^1.1.3",
    "cheerio": "^1.0.0-rc.12",
    "nodemon": "^2.0.20"
  }

 

답변 2

·

답변을 작성해보세요.

0

cafe small house님의 프로필

cafe small house

2023.03.03

이미 해결하신지는 모르겠지만 typescript 환경인가요? import cheerio from "cheerio" 이라 하지마시고 import * as cheerio from "cheerio" 로 해보시면 될거 같습니다

 

/ ES6 or TypeScript:
import * as cheerio from 'cheerio';

// In other environments:
const cheerio = require('cheerio');

const $ = cheerio.load('<ul id="fruits">...</ul>');

$.html();
//=> <html><head></head><body><ul id="fruits">...</ul></body></html>

0

해당 방식은 deprecated된 방식이 아닌데 희한하네요. 일단 정식버전을 쓰고계시지 않아서 정식버전 나올 때까지는 봐야할 것 같습니다.