-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcraw.js
89 lines (74 loc) · 3.01 KB
/
craw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const axios = require("axios");
const cheerio = require("cheerio");
// 아래 portalCrawler로 복지, 채용, 금융, 주거, 문화 크롤링
// 복지: https://www.daejeonyouthportal.kr/biz/businessIntro.do?dpmSectionFst=2&dpmSectionScd=10&commonMenuNo=79_92
// 채용: https://www.daejeonyouthportal.kr/biz/businessIntro.do?dpmSectionFst=1&dpmSectionScd=4&commonMenuNo=36_37
// 금융: https://www.daejeonyouthportal.kr/biz/businessIntro.do?dpmSectionFst=1&dpmSectionScd=8&commonMenuNo=36_281
// 주거: https://www.daejeonyouthportal.kr/biz/businessIntro.do?dpmSectionFst=2&dpmSectionScd=9&commonMenuNo=79_80
// 문화: https://www.daejeonyouthportal.kr/biz/businessIntro.do?dpmSectionFst=2&dpmSectionScd=11&commonMenuNo=79_112
const URLs = [
"https://www.daejeonyouthportal.kr/biz/businessIntro.do?dpmSectionFst=2&dpmSectionScd=10&commonMenuNo=79_92",
];
function portalCrawler() {
const URL = `https://www.daejeonyouthportal.kr/biz/businessIntro.do?dpmSectionFst=2&dpmSectionScd=10&commonMenuNo=79_92`;
const dataList = [];
axios
.get(URL)
.then((response) => {
const $ = cheerio.load(response.data);
$(".bd_thum.type01.type_biz li").each((index, element) => {
const title = $(element).find(".cont_tit span").text().trim();
const status = $(element).find(".state_04").text().trim();
const link = $(element).find("a").attr("href");
const imgSrc = $(element).find(".info_thum i img").attr("src");
let applyPeriod = "";
$(".cont_etc span").each((index, spanElement) => {
const spanText = $(spanElement).text().trim();
if (spanText.includes("신청기간")) {
applyPeriod = $(spanElement).find("i").text().trim();
}
});
const data = {
title: title,
link: link,
status: status,
imgSrc: imgSrc,
applyPeriod: applyPeriod,
};
dataList.push(data);
});
console.log(dataList);
})
.catch((error) => {
console.error("Error fetching data:", error);
});
}
portalCrawler();
// // 복지 페이지에 이용
// function healingCrawler() {
// const URL = "https://daejeon.pass.or.kr/healing.es?mid=a10102000000";
// const dataList = [];
// axios
// .get(URL)
// .then((response) => {
// const $ = cheerio.load(response.data);
// $(".dbody ul").each((index, element) => {
// const title = $(element).find(".title a").text().trim();
// const status = $(element).find(".state.ing").text().trim();
// const applyPeriod = $(element).find(".W20.m-br").eq(0).text().trim();
// const link = $(element).find(".title a").attr("href");
// const data = {
// title: title,
// status: status,
// applyPeriod: applyPeriod,
// link: link,
// };
// dataList.push(data);
// });
// console.log(dataList);
// })
// .catch((error) => {
// console.error("Error fetching data:", error);
// });
// }
// healingCrawler();