mmyjh86

[러닝-스크래핑5기] KRX 데이터 모으기

May 11th, 2020
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from pykrx import stock
  2. import time
  3. import os
  4.  
  5. for directory in ["per", "price"]:
  6.     if not os.path.exists(directory):
  7.         os.mkdir(directory)
  8.  
  9. for year in range(2000, 2019):
  10.     for mon in range(1, 13):
  11.         영업일 = stock.get_business_days(year, mon)
  12.         print(f"{영업일[0]} ~ {영업일[-1]}")
  13.  
  14.         df = stock.get_market_fundamental_by_ticker(영업일[0])
  15.         df.to_excel(f"per/{영업일[0].strftime('%Y%m%d')}.xlsx")
  16.  
  17.         df = stock.get_market_price_change_by_ticker(영업일[0], 영업일[-1])
  18.         df.to_excel(f"price/{영업일[0].strftime('%Y%m%d')}.xlsx")
  19.         time.sleep(1)
RAW Paste Data