개발/python

python - 다음 일봉 크롤링

xwing 2020. 12. 19. 09:21

파이썬으로 다음사이트에서 일봉을 크롤링해와 봅시다~~

# 다음 금융 일봉 크롤링
import requests
from bs4 import BeautifulSoup
import json

url = 'https://finance.daum.net/api/charts/A066570/days?limit=200&adjusted=true'
headers = {
    "referer": "https://finance.daum.net/chart/A005930",
    "user-agent": "Mozilla/5.0"
}

params = {
    "limit": "200",
    "adjusted": "true"
}

r = requests.get(url, headers=headers, params=params)
szContent = r.text
print (szContent)

#soup = BeautifulSoup(html, 'html.parser')
#titles = soup.select('span')

str_list = []
list = json.loads(szContent)
for price in list["data"]:
    str_list.append(price["symbolCode"])
    str_list.append(" ")
    str_list.append(price["date"])
    str_list.append(" : ")
    str_list.append(str(price["tradePrice"]).replace(".0", ""))
    str_list.append(" 원\n")

print("".join(str(v) for v in str_list))

GIST 보기

 

py_cl_dm.py

GitHub Gist: instantly share code, notes, and snippets.

gist.github.com

 

 

결과

이상~ 끝

'개발 > python' 카테고리의 다른 글

[python 기초] 엑셀에 구구단 출력하기  (0) 2021.01.05
파이썬 - pandas LG전자 일봉가져오기  (0) 2020.12.29
yahoo finance 크롤링  (0) 2020.12.19