Skip to content
컴퓨터잡담
2021.06.05 12:33

파이썬으로 네이버 증권정보 추출하기

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

단축키

Prev이전 문서

Next다음 문서

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

단축키

Prev이전 문서

Next다음 문서

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

파이썬으로 네이버 증권정보 추출하기

 

import time
from unicodedata import lookup #time 명령어 사용하기 
from bs4 import BeautifulSoup # BeautifulSoup 불러오기
#파이썬 requests 모듈은 간편한 HTTP 요청처리를 위해 사용하는 모듈로 별도로 설치해 주어야 한다.
import requests #pip3 install requests
 
search_data = "140520"
url = "https://navercomp.wisereport.co.kr/v2/company/c1010001.aspx?cmp_cd=" + search_data + "&cn="
html = requests.get(url)
bs_html = BeautifulSoup(html.content,"html.parser")

#종목명
search_name = bs_html.select("span")[2].text
#print(search_name)
 
#현재가 추출
nowval = bs_html.select("tr")[3]
now = nowval.select("strong")[0].get_text(" "strip=True)
 
#eps, bps, per, bpr, 배당정보 추출
val_rs = bs_html.select("td")[2]
eps = val_rs.select("dt b.num")[0].text
bps = val_rs.select("dt b.num")[1].text
per = val_rs.select("dt b.num")[2].text
upper = val_rs.select("dt b.num")[3].text
pbr = val_rs.select("dt b.num")[4].text
allocation = val_rs.select("dt b.num")[5].text
print(now + " ||| " + eps + " ||| " + bps + " ||| " + per + " ||| " + upper + " ||| " + pbr + " ||| " + allocation)
 
#대주주 지분율 추출
Shareholder_re = bs_html.select("tr")[19]
Shareholder = Shareholder_re.select("td")[2].get_text(" "strip=True)
 
#기업 내용
contents = bs_html.select("div.cmp_comment li")
content = ""
for i in contents:
    content = content + i.text #contents변수가 i변수로 대체되니 파이썬만의 특이함이 새롭다.
    
print(content)


 
#결과값 스프레드로 전달하기
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = [
'https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive',
]
json_file_name = 'C:\\Users\\크리스퍼\\python_code\\스프레드시트json키.json'
credentials = ServiceAccountCredentials.from_json_keyfile_name(json_file_namescope)
gc = gspread.authorize(credentials)
spreadsheet_url = '스프레드시트 파일 주소'
# 스프레스시트 문서 가져오기 
doc = gc.open_by_url(spreadsheet_url)
# 시트 선택하기
worksheet = doc.worksheet('관심종목')
 
#print(now + " ||| " + eps + " ||| " + bps + " ||| " + per + " ||| " + upper + " ||| " + pbr + " ||| " + allocation)
worksheet.insert_row(['1'search_datasearch_namenowepsbpsperpbrallocationShareholdercontent], 4)
로그인 후 댓글쓰기가 가능합니다.

?

  1. 08
    Jan 2015
    23:24

    XP USB 부팅디스크 만들기 & 고스트

    CategoryWindowsTip Views2089
    Read More
  2. 19
    Apr 2016
    19:49

    XE <title>제목 - 사이트명</title> 으로 변경방법

    CategoryServer Views2055
    Read More
  3. 14
    Jun 2021
    12:02

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

    Category컴퓨터잡담 Views2043
    Read More
  4. 16
    Jun 2021
    07:51

    파이썬 파라미터 변수값 전달받기

    Category컴퓨터잡담 Views2040
    Read More
  5. 17
    Feb 2016
    23:30

    오토셋과 apmsetup

    CategoryServer Views2026
    Read More
  6. 01
    Mar 2015
    23:15

    멀티부팅 USB 만들기

    CategoryWindowsTip Views2005
    Read More
  7. 26
    Mar 2016
    09:35

    XCOPY로 중요파일 백업하기

    CategoryServer Views1978
    Read More
  8. 22
    Jan 2015
    13:42

    공유기의 공인IP(Wan) 미할당으로 안되는 증상이 잦은경우 대처방법

    CategoryWindowsTip Views1967
    Read More
  9. 11
    Sep 2021
    13:43

    파이썬 any, all 사용하기(배열데이터 안에 값이 하나라도 있는지 또는 모두 있는지 비교)

    Category파이썬 Views1956
    Read More
  10. 13
    Jul 2015
    23:23

    파일 업로드 폴더 변경

    CategoryServer Views1953
    Read More
  11. 07
    Sep 2016
    12:49

    XE Request 줄이기

    CategoryServer Views1937
    Read More
  12. 20
    Mar 2015
    23:41

    ISO USB 굽기 최고의 프로그램

    CategoryWindowsTip Views1903
    Read More
  13. 05
    Jun 2021
    12:33

    파이썬으로 네이버 증권정보 추출하기

    Category컴퓨터잡담 Views1874
    Read More
  14. 19
    Apr 2016
    23:19

    XE Content font-size:수정방법

    CategoryServer Views1864
    Read More
  15. 12
    Mar 2021
    20:22

    [파이썬] 설치 및 사용방법

    Category컴퓨터잡담 Views1859
    Read More
  16. 06
    Sep 2021
    14:19

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

    Category파이썬 Views1853
    Read More
  17. 07
    Mar 2016
    23:25

    PHP Opcache 속도개선 시키기

    CategoryServer Views1829
    Read More
  18. 22
    Jan 2015
    13:07

    usb 쓰기가 금지되어 있습니다 해제방법

    CategoryWindowsTip Views1827
    Read More
  19. 02
    Jun 2021
    14:05

    파이썬 웹페이지 기업정보 추출하기

    Category컴퓨터잡담 Views1823
    Read More
  20. 27
    Dec 2014
    08:59

    윈도우 빠른종료 팁

    CategoryWindowsTip Views1823
    Read More
Board Pagination Prev 1 ... 40 41 42 43 44 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소