mmyjh86

[러닝-스크래핑2기] 아이투자 재무제표

Mar 6th, 2020
109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. from selenium import webdriver
  3.  
  4. id = "YOUR-ID"
  5. pw = "YOUR-PW"
  6.  
  7. driver = webdriver.Chrome('chromedriver.exe')
  8. driver.get('http://www.itooza.com/')
  9.  
  10. # 로그인
  11. ui = driver.find_element_by_css_selector("#cid")
  12. ui.send_keys(id)
  13. ui = driver.find_element_by_css_selector("#cpw")
  14. ui.send_keys(pw)
  15.  
  16. ui = driver.find_element_by_css_selector("#certify > form > div.login-box-wrap > div.btn-login > input[type=image]")
  17. ui.click()
  18.  
  19. # 재무제표 페이지로 이동
  20. ticker = "006800"
  21. driver.get(f'http://www.itooza.com/vclub/y10_page.php?cmp_cd={ticker}&mode=dy&ss=10&sv=1')
  22.  
  23. ## 하나의 값을 읽기
  24. ui = driver.find_element_by_css_selector("#node-1 > td:nth-of-type(2)")
  25. print(ui.text)
  26.  
  27. ui = driver.find_element_by_css_selector("#node-1 > td:nth-of-type(3)")
  28. print(ui.text)
  29.  
  30. # 전체를 데이터 프레임으로 읽기
  31. html = driver.page_source
  32. dfs = pd.read_html(html)
  33. print(dfs[2].head())
RAW Paste Data