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