(PYTHON) 공공데이터 포털사이트에 제공해주는 API를 뽑아오기

2020. 11. 12. 14:16PYTHON

www.data.go.kr/

 

공공데이터 포털

국가에서 보유하고 있는 다양한 데이터를『공공데이터의 제공 및 이용 활성화에 관한 법률(제11956호)』에 따라 개방하여 국민들이 보다 쉽고 용이하게 공유•활용할 수 있도록 공공데이터(Datase

www.data.go.kr

회원가입후

 

원하는 데이터를 활용신청하여 인증키를 발급후 

 

원하는데이터를 제공받는다 

 

from bs4 import BeautifulSoup
import urllib.request as req

import os.path

#XML 제공해주는 url 과 인증키를 넣어주면된다
url =""

fileName = "test1.xml"

if not os.path.exists(fileName):
 req.urlretrieve(url, fileName)

# 다운받은 파일을 분석하기

xml_data = open(fileName, "r", encoding="utf-8").read()

soup = BeautifulSoup(xml_data,'html.parser')

# 데이터 산출

for body in soup.find_all("body"):
    # body 에서 리스트 불러옴
    id = body.find('link_id')
    rate =body.find('ocpy_rate')
    sped = body.find('sped')
    stat_dt =body.find('stat_dt')
    print("제주도 교통정보 일간 통계")

    print("구간ID",id.string)
    print("점유율",rate.string)
    print("평균속도",sped.string)
    print("통계일시",stat_dt.string)

 

'PYTHON' 카테고리의 다른 글

(PYTHON) 데이터 형식  (0) 2020.11.13
(PYTHON) selenium을 이용한 자동 로그인 ,검색처리  (0) 2020.11.09
(python)selenium  (0) 2020.11.09
(PYTHON)데이터 크롤링  (0) 2020.11.04
(PYTHON)데이터 시각화  (0) 2020.11.03