반응형
기상청의 RSS를 파싱에 'cheerio-httpcli' 를 사용하여 뿌려주는 방법
다운로드 : weather.js
RSS URL : http://web.kma.go.kr/weather/forecast/mid-term-rss3.jsp?stnId=109
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 |
// 기상청 기상예보 RSS(cheerio이용) for Node.js
// 기상 RSS
var RSS = "http://web.kma.go.kr/weather/forecast/mid-term-rss3.jsp?stnId=109";
// 모듈 로드
var client = require('cheerio-httpcli');
// RSS 다운로드
client.fetch(RSS, {}, function(err, $, res) {
if (err) {
console.log("error"); return;
}
var city = $("location:nth-child(1) > city").text();
// 필요한 항목을 추출해서 표시
$("location:nth-child(1) > data").each(function(idx) {
var tmEf = $(this).find('tmEf').text();
var wf = $(this).find('wf').text();
var tmn = $(this).find('tmn').text();
var tmx = $(this).find('tmx').text();
console.log(city + " " + tmEf + " " + wf + " " + tmn +"~" + tmx);
});
});
|
cs |
결과
반응형
'프로그래밍 > Node.js' 카테고리의 다른 글
CasperJS 설치 (0) | 2017.04.07 |
---|---|
PhantomJS 설치 (0) | 2017.04.07 |
HTML 파일에서 링크 추출 (0) | 2017.03.27 |
node.js 특정 페이지 출력하는 코드 (0) | 2017.03.27 |
윈도우에서 'Node.js'와 'NPM'을 설치하기 (0) | 2017.03.25 |