Skip to content
컴퓨터잡담
2021.08.22 11:39

파이썬 다음 증권의 주가 가져오기

조회 수 1452 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

파이썬 다음 증권의 주가 가져오기

 

 

import requests
import json
import pandas as pd
 
def get_price(coden):
    # DATA를 불러오는 부분 입니다.
    url = 'http://finance.daum.net/api/charts/A%s/days?limit=%d&adjusted=true'%(coden)
    headers = {
                'Accept''application/json, text/plain, */*',
                'Accept-Encoding''gzip, deflate',
                'Accept-Language''ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7',
                'Connection''keep-alive',
                'Cookie''GS_font_Name_no=0; GS_font_size=16; _ga=GA1.3.937989519.1493034297; webid=bb619e03ecbf4672b8d38a3fcedc3f8c; _ga=GA1.2.937989519.1493034297; _gid=GA1.2.215330840.1541556419; KAKAO_STOCK_RECENT=[%22A069500%22]; recentMenus=[{%22destination%22:%22chart%22%2C%22title%22:%22%EC%B0%A8%ED%8A%B8%22}%2C{%22destination%22:%22current%22%2C%22title%22:%22%ED%98%84%EC%9E%AC%EA%B0%80%22}]; TIARA=C-Tax5zAJ3L1CwQFDxYNxe-9yt4xuvAcw3IjfDg6hlCbJ_KXLZZhwEPhrMuSc5Rv1oty5obaYZzBQS5Du9ne5x7XZds-vHVF; webid_sync=1541565778037; _gat_gtag_UA_128578811_1=1; _dfs=VFlXMkVwUGJENlVvc1B3V2NaV1pFdHhpNTVZdnRZTWFZQWZwTzBPYWRxMFNVL3VrODRLY1VlbXI0dHhBZlJzcE03SS9Vblh0U2p2L2V2b3hQbU5mNlE9PS0tcGI2aXQrZ21qY0hFbzJ0S1hkaEhrZz09--6eba3111e6ac36d893bbc58439d2a3e0304c7cf3',
                'Host''finance.daum.net',
                'If-None-Match''W/"23501689faaaf24452ece4a039a904fd"',
                'Referer''http://finance.daum.net/quotes/A069500',
                'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'
                }
    headers['Referer'] = 'http://finance.daum.net/quotes/A%s'%code
    r = requests.get(urlheaders = headers)
    
    # DATA를 보기 좋게 편집하는 부분 입니다.
    data = json.loads(r.text)
    df = pd.DataFrame(data['data'])
    df.index = pd.to_datetime(df['candleTime'])
    
    return df

print(get_price('006980',5))

 

결과는 최근 5일간의 가격정보를 가져옵니다.

Copyright (C) Microsoft Corporation. All rights reserved.

새로운 크로스 플랫폼 PowerShell 사용 https://aka.ms/pscore6
PS H:\python\py_code> & H:/python/python.exe h:/python/py_code/카카오라인/다음증권.py
symbolCode        date             candleTime  tradePrice  openingPrice  highPrice  lowPrice  candleAccTradePrice  candleAccTradeVolume tradeTime      timestamp change  changeRate  changePrice
candleTime
2021-08-13    A006980  2021-08-13  2021-08-13 00:00:00.0     33500.0       34250.0    34450.0   32950.0            800479000                 23991    153030  1629150648065   FALL    0.021898        750.0
2021-08-17    A006980  2021-08-17  2021-08-17 00:00:00.0     32250.0       33650.0    33850.0   31850.0            950686500                 29343    153012  1629237048540   FALL    0.037313       1250.0
2021-08-18    A006980  2021-08-18  2021-08-18 00:00:00.0     32450.0       31600.0    32650.0   31600.0            507615050                 15699    153030  1629323449741   RISE    0.006202        200.0
2021-08-19    A006980  2021-08-19  2021-08-19 00:00:00.0     31100.0       32200.0    32500.0   30800.0            811751150                 25806    153030  1629409848895   FALL    0.041602       1350.0
2021-08-20    A006980  2021-08-20  2021-08-20 00:00:00.0     29850.0       31200.0    31450.0   29700.0            938633350                 31126    153026  1629451601975   FALL    0.040193       1250.0
PS H:\python\py_code> 

 

https://steemit.com/kr/@thrufore/python-daum--1541574674320

 

로그인 후 댓글쓰기가 가능합니다.

?

List of Articles
번호 분류 제목 날짜 조회 수
77 [Docs]스프레드시트 스프레드시트에서 수정, 삭제 버튼 만들기 2023.03.09 1820
76 Server xe 타이틀 게시판 이름 없애기 file 2016.06.28 1803
75 Server Apache에 대한 mod_proxy 지원 구성 2016.09.06 1801
74 컴퓨터잡담 파이썬 사이트 정보 가져와서 필요한 내용 추출하기 2021.05.31 1779
73 WindowsTip 컴퓨터가 많이 느리다면? 2015.01.08 1777
72 WindowsTip 윈도우 XP SP3 와 Windows 8.1 두가지 부팅 메뉴얼 file 2015.02.11 1768
71 컴퓨터잡담 KM Wakeup 절전모드 예약 및 깨우는 프로그램 file 2021.07.08 1763
70 파이썬 키움증권 OpenAPI 당황스러움 file 2021.09.06 1747
69 Server 서버 부하상태 체크 file 2016.04.30 1709
68 컴퓨터잡담 파이썬 리스트에 데이터 삽입하기 2021.06.22 1707
67 WindowsTip 익스플로러 ftp 정상화 시키기 file 2014.12.23 1660
66 [Docs]스프레드시트 스프레드시트의 값의 변화에 따라 지메일로 메일을 보내는 스크립트 2023.03.10 1660
65 Server [Apache] mod_expires .htaccess을 수정하여 브라우저 캐싱하기 2016.03.16 1657
64 Server XE file cache 활용 2016.08.19 1648
63 WindowsTip IE 익스플로러 메뉴 바탕이 검정색으로 변했을경우 대처방법 2 2015.01.27 1644
62 Server [아파치 error.log] Fatal Error Unable to reattach to base address file 2016.03.25 1643
61 컴퓨터잡담 파이썬 한우정액 정보 스프레드로 추출하기 file 2021.06.05 1625
60 컴퓨터잡담 파이썬 멀티라벨 소스 줄이기 2021.06.23 1616
59 컴퓨터잡담 Python 파일을 exe파일로 컴파일하기 2021.06.16 1611
58 컴퓨터잡담 [python] 윈도우 파이썬 모듈 설치 방법 (특정프로그램 설치 없이 기본프로그램 활용) 2021.09.02 1580
Board Pagination Prev 1 ... 41 42 43 44 45 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소