Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
네이버 금융에서 일별 종가를 읽어오는 클래스 ( 참고 - 이걸 그대로 클래스로 구현함)
## 참고 (거의 그대로 가져옴)
import urllib
import time
import sys
from urllib import urlopen
from bs4 import BeautifulSoup
class NaverStockCrawler(object):
"""네이버 금융에서 일별 종가를 읽어오는 클래스"""
def __init__(self, stock_item):
self.stock_item = stock_item
self.url = ''+ stock_item
self.items = OrderedDict()
def get(self, days=40):
url = ''+ self.stock_item
html = urlopen(self.url)
source = BeautifulSoup(, "html.parser")
maxPage=source.find_all("table", align="center")
mp = maxPage[0].find_all("td", class_="pgRR")
mpNum = int(mp[0].a.get('href')[-3:])
pages = days//10 if days%10==0 else days//10 + 1
for page in range(1, pages+1):
sys.stdout.write("\r* crawling page " + str(page) + "...")
page_url = self.url +'&page='+ str(page)
html = urlopen(page_url)
source = BeautifulSoup(, "html.parser")
isCheckNone = None
if((page % 1) == 0):
for i in range(1,len(srlists)-1):
if(srlists[i].span != isCheckNone):
date = srlists[i].find_all("td",align="center")[0].text
price = srlists[i].find_all("td",class_="num")[0].text
self.items[date] = float(price.replace(",", ""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment