Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

기록

Naver에서 주식 종목별 시세 가져오기 본문

Language/python

Naver에서 주식 종목별 시세 가져오기

민동기 2019. 5. 4. 14:03
728x90

CODE는 종목 코드

PAGES는 몇 page data를 가져올지 정의

 

reference: https://excelsior-cjh.tistory.com/109

def get_sise(CODE,PAGES):
	url='http://finance.naver.com/item/sise_day.nhn?code={code}'.format(code=CODE)
	ref=pd.DataFrame()
	for page in range(1, PAGES): 
	pg_url='{url}&page={page}'.format(url=url, page=page) 
	ref=ref.append(pd.read_html(pg_url, header=0)[0], ignore_index=True) 
	ref=ref.dropna()
	ref.columns= ['date', 'close', 'diff', 'open', 'high', 'low', 'volume']
    del ref['diff']
	ref[['close', 'open', 'high', 'low', 'volume']] = \
    	ref[['close', 'open', 'high', 'low', 'volume']].astype(int)
	ref['date']=pd.to_datetime(ref['date']) 
	return ref