Thief of Wealth

네이버에서 KPI200지수 데이터 긁어오기를 해봅시다.


# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

index_code = "KPI200" # KPI200 지수 코드입니다.
page_number = 1

# 긁어올 naver 금융 중에 KPI200지수 시세입니다.
naver_url = 'http://finance.naver.com/sise/sise_index_day.nhn?code=' + index_code + '&page=' + str(page_number)


from urllib.request import urlopen
source = urlopen(naver_url).read() # 긁어 와보리기
#print(source)


# 이제 긁어왔으니 beautifulSoup로 분석할 차례
import bs4
source = bs4.BeautifulSoup(source, 'lxml')
#print(source.prettify())

# html코드중에 테이블 속성에 td태그를 불러올것임!
td = source.find_all('td')
# print(len(td)) # 54개나있네

# 날짜 부분 1개 추출
d = source.find_all('table')[0].find_all('tr')[2].find_all('td')[0]
print(d)




그러니까 순서는 url따고, 

python으로 url불러오고

beautifulsoup으로 조작하는 것이다.





본 글은 "파이썬으로 배우는 금융공학 레시피"를 기준으로 작성되었습니다.

profile on loading

Loading...