금융감독원 API 활용 샘플

 

# -*- coding: utf-8 -*-

# @ 금융감독원 API 를 이용 한 삼성전자 2021 년 임직원 현황 정보 가져오기 (샘플 )

import requests
import xml.etree.ElementTree as ET
import matplotlib
import matplotlib.font_manager as fm
import matplotlib.pyplot as plt
from pprint import pprint

# 다트 - 공시 API
apiKey = "---------------------------------"

## 호출하려는 OpenAPI URL를 정의합니다.
url = "https://opendart.fss.or.kr/api/empSttus.xml?crtfc_key=" + apiKey + "&corp_code=00126380&bsns_year=2021&reprt_code=11011"

response = requests.get(url)

### http 통신 결과 코드 확인
print("response.status_code : " + str( response.status_code ) )

## http 요청이 성공했을때 API의 리턴값을 가져옵니다.
if response.status_code == 200:
    contents = response.text
    # print("@@@@@ API 수신 문자열(XML) @@@@@")
    pprint(str(contents))
    ecosRoot = ET.fromstring(contents)
    #print(str(len(ecosRoot)))


for row in ecosRoot.iter("list"):
    print("-----------------------------------------------------------------------------------------------")
    print( "접수번호:" + str(row.find('rcept_no').text) )
    print( "법인구분 : Y(유가), K(코스닥), N(코넥스), E(기타):" + str(row.find('corp_cls').text) )
    print( "공시대상회사의 고유번호(8자리):" + str(row.find('corp_code').text) )
    print( "법인명:" + str(row.find('corp_name').text) )
    print( "성별 남, 여:" + str(row.find('sexdstn').text) )
    print( "사업부문:" + str(row.find('fo_bbm').text) )
    print( "개정 전 직원 수 정규직:" + str(row.find('reform_bfe_emp_co_rgllbr').text) )
    print( "개정 전 직원 수 계약직:" + str(row.find('reform_bfe_emp_co_cnttk').text) )
    print( "개정 전 직원 수 기타:" + str(row.find('reform_bfe_emp_co_etc').text) )
    print( "정규직 수	상근, 비상근:" + str(row.find('rgllbr_co').text) )
    print( "정규직 단시간 근로자 수	대표이사, 이사, 사외이사 등:" + str(row.find('rgllbr_abacpt_labrr_co').text) )
    print( "계약직 수:" + str(row.find('cnttk_co').text) )
    print( "계약직 단시간 근로자 수:" + str(row.find('cnttk_abacpt_labrr_co').text) )
    print( "합계:" + str(row.find('sm').text) )
    print( "avrg_cnwk_sdytrn:" + str(row.find('avrg_cnwk_sdytrn').text) )
    print( "연간 급여 총액:" + str(row.find('fyer_salary_totamt').text) )
    print( "1인평균 급여 액:" + str(row.find('jan_salary_am').text) )