https://www.youtube.com/watch?v=B7pFsal9Zn0&list=PLAdQRRy4vtQREMg7H7-zFPSOYS6xF1gIL&index=25
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse
# 네이버금융 - 리팩토링 function으로 묶기
def get_bs_obj(company_code):
url = "https://finance.naver.com/item/main.nhn?code="+company_code
result=requests.get(url)
bs_obj=BeautifulSoup(result.content,"html.parser")
return bs_obj
# company_code를 받아서 price를 return하는 함수
def get_price(company_code):
bs_obj=get_bs_obj(company_code)
no_today=bs_obj.find("p",{"class":"no_today"})
no_today_span=no_today.find("span",{"class":"blind"})
return no_today_span.text
# print("samsung price : "+get_price("005930"))
# print("debec price : "+get_price("006370"))
# print("hynix price : "+get_price("000660"))
company_codes={"samsung price : ":"005930","debec price : ":"006370","hynix price : ":"000660"}
for company_name,company_price in company_codes.items():
print(company_name+get_price(company_price))
'컴퓨터 > Python' 카테고리의 다른 글
| 네이버 금융 시고저종 (0) | 2019.06.24 |
|---|---|
| python findAll (0) | 2019.06.24 |
| 네이버금융 주식종목 가격가져오기 (0) | 2019.06.23 |
| naverAPI simple code (0) | 2019.06.23 |
| json viewer (0) | 2019.06.23 |