express 크롤링

김기태·2021년 10월 13일
0

예시

try {
await axios({
url: url,
method: "GET",
responseType: "arraybuffer",
}).then(async (html) => {
const content = iconv.decode(html.data, "EUC-KR").toString();
const $ = cheerio.load(content);
const list = $("ol li");
await list.each( async (i, tag) => {
let desc = $(tag).find("p.copy a").text()
let image = $(tag).find("p.image a img").attr("src")
let title = $(tag).find("p.image a img").attr("alt")
let price = $(tag).find("p.price strong").text()
})
});
res.send({ result: "success", message: "크롤링이 완료 되었습니다." });
} catch (error) {
console.log(error)
res.send({ result: "fail", message: "크롤링에 문제가 발생했습니다", error:error });
}
});
profile
김개발

0개의 댓글