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. 아파치 ab 로 성능테스트 하기

  2. 8기가 램에 맞는 Mysql config 셋팅 값

  3. LG G5 기능 어디한번 보자

  4. 오토셋과 apmsetup

  5. Sitemap.xml 만들어 주는 사이트

  6. ES 파일 탐색기로 FTP 동영상 재생하기

  7. Diskless Boot Software for Windows(윈도우용 노하드 시스템)

  8. ACTIVE-X 의 무서움

  9. 서버 다운 원인

  10. 엑셀 지정행 반복인쇄 하는 방법[지정행/지정열]

  11. [안드로이드] 키캣 4.4 버전 플래시 동영상 안될때 해결방법

  12. PC에 안드로이드 설치하기

  13. 안드로이드 플래시 동영상이 안될때 해결방법 [200, Stream not found, NetStream.Play.StreamNotFound, clip: '[Clip] ...Progress]

  14. [오류해결방법] 200, Stream not found, NetStream.Play.StreamNotFound, clip: '[Clip] ...

  15. Windows APM Install(Apache 2.4, PHP 6.0, Mysql) 최신버전 설치해보기

  16. Google 문서도구를 컴퓨터에 동기화

  17. 박지성 맨유시절 호날두와의 호흡경기 모음(유니세프 친선경기)

  18. 도스 배치파일로 원격지 컴퓨터 모니터링

  19. DOS Batch - FTP Scripts 배치파일

  20. 엑셀 깨진파일 복구하기

Board Pagination Prev 1 ... 11 12 13 14 15 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소