참고링크
http://blog.quantylab.com/2020-10-09-dart.html
https://github.com/josw123/dart-fss
https://dart-fss.readthedocs.io/en/latest/dart_fs.html#id2
https://dotsnlines.tistory.com/739?category=955042
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import dart_fss as dart
# Open DART API KEY 설정
api_key=#your api key#
dart.set_api_key(api_key=api_key)
# DART 에 공시된 회사 리스트 불러오기
corp_list = dart.get_corp_list()
# 삼성전자 검색
samsung = corp_list.find_by_corp_name('삼성전자', exactly=True)[0]
# 2012년부터 연간 연결재무제표 불러오기
fs = samsung.extract_fs(bgn_de='20190101', fs_tp=('bs','is','cf'))
filename='fs_samsung.xlsx'
path = '파일경로'
# 재무제표 검색 결과를 엑셀파일로 저장 ( 기본저장위치: 실행폴더/fsdata )
fs.save(filename,path)
|
cs |
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
from openpyxl import Workbook,load_workbook
import pandas as pd
#삼성 재무정보파일 호출
file='fs_samsung.xlsx'
wb=load_workbook(file)
#필요한 데이터 레이블
bs_items=['ifrs-full_Assets','ifrs-full_Liabilities','ifrs-full_Equity']
is_items=['ifrs-full_Revenue','dart_OperatingIncomeLoss','ifrs-full_ProfitLoss']
cf_items=['ifrs-full_CashFlowsFromUsedInOperatingActivities']
ws_bs=wb['Data_bs']
y_list=[]
c= 10
while ws_bs.cell(2,c).value != None:
y=ws_bs.cell(1,c).value
y_list.append(y)
c+=1
print(y_list)
df_list=[]
for bs_item in bs_items:
temp_list=[]
r=4
while ws_bs.cell(r,2).value !=None:
if ws_bs.cell(r,2).value==bs_item:
item=ws_bs.cell(r,3).value
c=10
while ws_bs.cell(1,c).value !=None:
temp_list.append(ws_bs.cell(r,c).value)
c+=1
r+=1
df=pd.DataFrame({item:temp_list},index=y_list)
df_list.append(df)
ws_is=wb['Data_is']
for is_item in is_items:
temp_list=[]
r=4
while ws_is.cell(r,2).value !=None:
if ws_is.cell(r,2).value==is_item:
item=ws_is.cell(r,3).value
c=8
while ws_is.cell(1,c).value !=None:
temp_list.append(ws_is.cell(r,c).value)
c+=1
r+=1
df=pd.DataFrame({item:temp_list},index=y_list)
df_list.append(df)
ws_cf=wb['Data_cf']
for cf_item in cf_items:
temp_list=[]
r=4
while ws_cf.cell(r,2).value !=None:
if ws_cf.cell(r,2).value==cf_item:
item=ws_cf.cell(r,3).value
c=9
while ws_cf.cell(1,c).value !=None:
temp_list.append(ws_cf.cell(r,c).value)
c+=1
r+=1
df=pd.DataFrame({item:temp_list},index=y_list)
df_list.append(df)
total_df=pd.concat(df_list,axis=1)
total_df=total_df.transpose()
# col 생략 없이 출력
pd.set_option('display.max_columns', None)
print(total_df)
#파일 저장
#total_df.to_excel('재무정보상태표.xlsx')
|
cs |
다음과 같이 데이터를 뽑아서 엑셀파일로 저장할 수 있게 되었습니다.