프로젝트/개인 프로젝트 [세모이]
#3 현재
sungtt
2022. 1. 4. 03:35
사이트의 이벤트페이지를 크롤링하기위해
우선 크롤링 코드를 작성해보고있다.
node.js의 axios와 cheerio를 통하여 네이버 월요웹툰의 타이틀을 뽑아오려는중이다.
const axios = require('axios');
const cheerio = require('cheerio');
const getHtml = async() => {
try{
return await axios.get("https://comic.naver.com/webtoon/weekdayList?week=mon");
} catch(error){
console.error(error);
}
};
getHtml().then(
html => {
const $ = cheerio.load(html.data);
const $body = $("ul.img_list").children("li").children("dl").children("dt").children("a");
console.log($body.text())
});
위 코드의 출력 결과는 아래처럼 나온다.
현재 얕은지식으로 생각해본 사항들은
1. 뽑아온 a태그의 text들을 배열에 담아내는 방법이 뭘까?
2. 담아낸 배열을 json파일로 만들어 DB에 보내야하지않을까?
3. DB에 보냈다가, 서버를 통하여 html로 끌어온다면 화면에 출력이 가능해지는걸까?