mmyjh86

[러닝스푼즈] 다트 스크래핑

Sep 20th, 2019
152
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import dart_fss as dart
  2. import requests
  3. from bs4 import BeautifulSoup
  4.  
  5. api_key='YOUR_PRIVATE_KEY'
  6. dart.dart_set_api_key(api_key=api_key)
  7.  
  8. reports = dart.search_report(crp_cd= '005930', start_dt='20190101',
  9.                              bsn_tp='A002')
  10. for r in reports :
  11.     # -------------------------------------------------------------------------
  12.     # 회사의 개요 스크래핑
  13.     page = r.pages[3]
  14.     data = {
  15.         "rcpNo": page.rcp_no,
  16.         "dcmNo": page.dcm_no,
  17.         "eleId": page.ele_id
  18.     }
  19.  
  20.     url = "http://m.dart.fss.or.kr/report/main.do"
  21.     resp = requests.post(url, data=data)
  22.     html = resp.text
  23.     soup = BeautifulSoup(html, 'html5lib')
  24.  
  25.     result = soup.select("body > p:nth-child(4) > span:nth-child(4)")
  26.     print("회사의 법적, 상업적 명칭", result[0].text.strip())
  27.  
  28.     # -------------------------------------------------------------------------
  29.     # 연결 재무재표 스크래핑
  30.     page = r.pages[13]
  31.     data = {
  32.         "rcpNo": page.rcp_no,
  33.         "dcmNo": page.dcm_no,
  34.         "eleId": page.ele_id
  35.     }
  36.  
  37.     url = "http://m.dart.fss.or.kr/report/main.do"
  38.     resp = requests.post(url, data=data)
  39.     html = resp.text
  40.     soup = BeautifulSoup(html, 'html5lib')
  41.  
  42.     result = soup.select("body > table:nth-child(3) > tbody > tr:nth-child(2) > td:nth-child(3) > p")
  43.     print("유동자산:", result[0].text)
RAW Paste Data