FrontEnd 공공데이터활용지원센터_보건복지부 코로나19 감염 현황

공공데이터활용지원센터_보건복지부 코로나19 감염 현황

예전에 공공데이터 관련해서 크롤링해야흔 부분이 있었는데 node.js로 바로 크롤링한 데이터를 react로 전송했던 부분이 있어 코드를 공유하고자한다.

const getBreeds = async () => {
var url = 'http://openapi.data.go.kr/openapi/service/rest/Covid19/getCovid19InfStateJson';
var queryParams = '?' + encodeURIComponent('ServiceKey') + '=zWJGWsZTX%2FrJP6gryI%2FZZCnS23KP%2FaPF7IzFwYJlTUCKgq2AG3zkalo64Vc5Suf%2FUHoKciZw0dByIBDcP1WR%2Fg%3D%3D'; /* Service Key*/
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('10'); /* */
queryParams += '&' + encodeURIComponent('startCreateDt') + '=' + encodeURIComponent('20200310'); /* */
queryParams += '&' + encodeURIComponent('endCreateDt') + '=' + encodeURIComponent('20200315'); /* */
queryParams += '&' + encodeURIComponent('SEQ') + '=' + encodeURIComponent('30'); /* */
request({
url: url+queryParams,
method: 'GET'
}, function (error, response, body) {
//console.log('Status', response.statusCode);
//console.log('Headers', JSON.stringify(response.headers));
var result = body
var xmlToJson = convert.xml2json(result, {compact: true, spaces: 4});
var Json_result = xmlToJson
//console.log(`xml to json => ${xmlToJson}`)
console.log(`xml to json => ${xmlToJson.body}`)
const json = JSON.parse(parser.toJson(result))
const item = json.response.body.items.item[0]
console.log(item)
// console.table(item)
// const addrs = item.map(i => i.addr)
// const template = `l
// each addr in addrs
// li= addr
// `
// const html = pug.render(template, { addrs: addrs })
// console.log(html)
});
};
router.get('/data', function (req, res, next) {
getBreeds()
});
module.exports = router;

Leave a Reply

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

Related Post

[React] npx create-react-app 설치오류 “We no longer support global installation of Create React App”[React] npx create-react-app 설치오류 “We no longer support global installation of Create React App”

요새 도커로 개발하고 왠만한 개발환경들인 사전에 설치되어있어서 오랜만에 새프로젝트나 공부하려고 하다보니 설치오류가 종종발생한다 이처럼 버전문제가 항상 발생하는데 이때 발생하는 문제를 가볍게 해결할수 있는 방법을 몇가지 메모하고자한다. 방법 1. 12 npx clear-npx-cache

React 프로젝트 구조와 폴더 설명React 프로젝트 구조와 폴더 설명

React는 효율적인 UI 개발을 지원하는 강력한 라이브러리입니다. React 프로젝트를 체계적으로 관리하기 위해 적절한 폴더 구조를 설계하는 것은 매우 중요합니다. 이번 글에서는 React 프로젝트의 기본 구조와 주요 폴더의 역할에 대해 자세히