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

 

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

?

  1. 05
    Sep 2021
    09:06

    파이썬 변수전달하기

    Category파이썬 Views1446
    Read More
  2. 27
    Sep 2021
    11:35

    파이썬 변수내용 문자열 자르기 특이한 점

    Category파이썬 Views2965
    Read More
  3. 28
    Jul 2021
    09:10

    파이썬 변수값에서 숫자만 추출하기

    Category컴퓨터잡담 Views1141
    Read More
  4. 04
    Mar 2023
    08:47

    파이썬 변수가 정의되었는지 여부 확인방법코드

    Category파이썬 Views3982
    Read More
  5. 18
    Jun 2021
    08:44

    파이썬 문자열b 안에 변수 a를 대치시키려면 크게 세 가지 방법

    Category컴퓨터잡담 Views2582
    Read More
  6. 21
    Feb 2023
    06:32

    파이썬 모듈 업그레이드 명령어

    Category파이썬 Views3628
    Read More
  7. 23
    Jun 2021
    13:32

    파이썬 멀티라벨 소스 줄이기

    Category컴퓨터잡담 Views1616
    Read More
  8. 06
    Sep 2021
    14:19

    파이썬 매수할 피라미드 매수전략

    Category파이썬 Views1853
    Read More
  9. 22
    Jun 2021
    08:01

    파이썬 리스트에 데이터 삽입하기

    Category컴퓨터잡담 Views1707
    Read More
  10. 04
    Oct 2023
    23:29

    파이썬 랜덤으로 시험문제 풀기

    Category파이썬 Views72007
    Read More
  11. 04
    Oct 2023
    23:33

    파이썬 랜덤으로 문제풀기 #2

    Category파이썬 Views75541
    Read More
  12. 16
    Mar 2021
    19:21

    파이썬 동행복권 판매인 모집 공고 발생시 자동알림

    Category컴퓨터잡담 Views2272
    Read More
  13. 22
    Aug 2021
    11:39

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

    Category컴퓨터잡담 Views1452
    Read More
  14. 22
    Aug 2021
    10:19

    파이썬 네이버라인 메시지 보내기

    Category컴퓨터잡담 Views1479
    Read More
  15. 06
    Sep 2021
    22:26

    파이썬 네이버 증권 주식 현재가 가져오기

    Category컴퓨터잡담 Views1463
    Read More
  16. 21
    Nov 2022
    09:04

    파이썬 글자 인식, 파이썬 OCR, 파이썬 Tesseract 사용

    Category파이썬 Views14641
    Read More
  17. 08
    May 2022
    08:38

    파이썬 구글스프레드시트 값 불러오기 html로 변환작업 중!

    Category파이썬 Views20186
    Read More
  18. 14
    Jun 2021
    12:02

    파이썬 게시물 검색으로 새로운 게시물 등록시 지메일로 파일 보내기

    Category컴퓨터잡담 Views2043
    Read More
  19. 13
    Nov 2023
    05:45

    파이썬 requestsbeautifulsoup 으로 웹 input에 입력값 대입한 뒤 결과값 파일로 저장하기

    Category파이썬 Views63475
    Read More
  20. 29
    Sep 2023
    20:32

    파이썬 request, beautifulshop으로 정액정보 받아오기

    Category컴퓨터잡담 Views75698
    Read More
Board Pagination Prev 1 2 3 4 5 6 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소