· 5 years ago · May 13, 2020, 03:20 PM
1import requests
2import zipfile
3from bs4 import BeautifulSoup
4
5key = "YOUR API KEY"
6url = f"https://opendart.fss.or.kr/api/corpCode.xml?crtfc_key={key}"
7resp = requests.get(url)
8
9file = open("out.zip", "wb")
10file.write(resp.content)
11file.close()
12
13zf = zipfile.ZipFile("out.zip")
14zf.extractall()
15zf.close()
16
17file = open("CORPCODE.xml", "r", encoding="utf-8")
18data = file.read()
19file.close()
20
21bs = BeautifulSoup(data, 'html5lib')
22result = bs.select("corp_code")
23for item in result:
24 print(item.text)