티스토리 뷰

Requirements

 - Editor : VScode

 - python 3.10

 - requests 2.28.1 : builtin function

 - BeautifulSoup4 4.11.1 : pip3 install

 

 

1. 공공데이터포탈 회원가입 및 데이터 활용신청

web site : data.go.kr
검색어 굴뚝

 

데이터활용신청하기

오픈 API : 한국환경공단 굴뚝자동측정기기 측정결과

 

활용신청

 

마이페이지

... 아래 인증키 생성

 

 

code 작성에 필요한 요청변수 및 출력결과 예시

 

2. python code

# -*- coding: utf-8 -*-
# python3의 경우 삭제

from urllib.parse import urlencode, unquote
import requests
import pprint
import json


url = 'http://apis.data.go.kr/B552584/cleansys/rltmMesureResult'
idkey = '[YOURKEY]'
# queryString
queryString="?" + urlencode(
    {
    'serviceKey' : unquote(idkey),
    'areaNm' : '충청북도', 
    'factManageNm' : '한세이프에너지㈜',
    'stackCode' : '1', 
    'type' : 'json' 
    }
)

queryURL = url + queryString
response = requests.get(queryURL)
print(response)

r_dic = json.loads(response.text)
print(r_dic)

 

Terminal

<Response [200]>
{'response': {'header': {'resultCode': '0', 'totalCount': 1, 'resultMsg': 'NORMAL_CODE'}, 
'body': {'items': [{'nh3_mesure_value': None, 'mesure_dt': '2022-10-14 11:30', 
'nox_exhst_perm_stdr_value': '59.5', 'sox_mesure_value': '0.35', 
'hf_mesure_value': None, 'sox_exhst_perm_stdr_value': '24', 
'nox_mesure_value': '31.59', 'hcl_exhst_perm_stdr_value': '12', 
'tsp_exhst_perm_stdr_value': '16', 'area_nm': '충청북도', 
'nh3_exhst_perm_stdr_value': None, 'hf_exhst_perm_stdr_value': None, 
'co_mesure_value': '24.72', 'fact_manage_nm': '한세이프에너지㈜', 
'tsp_mesure_value': '4.51', 'stack_code': '1', 'hcl_mesure_value': '0.13', 
'co_exhst_perm_stdr_value': '180'}]}}}

 

json data가 출력되니 잘 요리해서 활용

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
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
글 보관함