node.js crawling

한결·2021년 5월 10일

크롤링 도구

const cheerio = require('cheerio');
const axios = require("axios"); //외부페이지 접속
const iconv = require('iconv-lite'); //한글깨짐방지
const url = "https://finance.naver.com/sise/lastsearch2.nhn"

주소추가

router.get("/crawling", function(req,res){

    axios({url:url,method:"GET",responseType:"arraybuffer"}).then(function(html){
        const content = iconv.decode(html.data,"EUC-KR").toString() //html 파싱한걸 한글깨짐방지
        const $ = cheerio.load(content) //html(content)를 cheerio로 불러옴
        const h3 = $(".tlt_page")
        console.log(div.text())
     
        res.send({success:200})
    })
    
})  
profile
개발

0개의 댓글