프로그래밍/Python

[Python] Open API

eunki 2021. 8. 22. 11:23
728x90

공공데이터 포털 OPEN API 사용하기

 

  1. 공공데이터 포털 로그인 (https://www.data.go.kr/)
  2. API 사용 요청 / 키 발급
  3. API 문서(specification) 확인
  4. API 테스트 및 개발
import requests

serviceKey = 'serviceKey123'
endpoint = 'http://api.visitkorea.or.kr/openapi/service/rest/EngService/areaCode?serviceKey={}&numOfRows=10&pageSize=10&pageNo={}&MobileOS=ETC&MobileApp=AppTest&_type=json'.format(serviceKey, 1)
resp = requests.get(endpoint)

data = resp.json()
print(data['response']['body']['items']['item'][0])  # {'code': 1, 'name': 'Seoul', 'rnum': 1}
728x90