Skip to content
조회 수 2244 추천 수 0 댓글 1
?

단축키

Prev이전 문서

Next다음 문서

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

단축키

Prev이전 문서

Next다음 문서

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

네이버 주식에서 종목의 투자정보 자료 가져오기

 

 

 

양지사 예제 url : https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=%EC%96%91%EC%A7%80%EC%82%AC


import requests
from bs4 import BeautifulSoup
 
url = 'https://finance.naver.com/item/main.naver?code=005930'
 
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
 
# 투자정보 탭의 첫 번째 테이블
table1 = soup.select_one('#tab_con1 > div:nth-child(2) > table')#id=tab_con1의 2번째div
table2 = soup.select_one('#tab_con1 > div:nth-child(3) > table')
table3 = soup.select_one('#tab_con1 > div:nth-child(4) > table')
table4 = soup.select_one('#tab_con1 > div:nth-child(5) > table')
table5 = soup.select_one('#tab_con1 > div:nth-child(6) > table')
 
print(table1,table2,table3,table4,table5)

 

결과:

PS C:\Users\Administrator> & c:/python/python.exe "c:/Python/py_code/주식정보/import requests.py"

<table summary="시가총액 정보">

<caption>시가총액</caption>

<tr class="strong">

<th scope="row">시가총액</th>

<td><em id="_market_sum">

 

 

 

 

 

 

                                                                               354조

 

                                                                                                                                                                                                                                                   6,051

 

 

                                                                </em>억원</td>

</tr>

<tr><th scope="row">

<a class="link_site" href="/sise/sise_market_sum.naver" onclick="clickcr(this, 'sop.19', '', '1', event)">시가총액순위</a>

</th><td>코스피 <em>1</em>위</td></tr>

<tr>

<th scope="row">상장주식수</th>

<td><em>5,969,782,550</em></td>

</tr>

<tr><th scope="row">액면가<span class="bar">l</span>매매단위</th>

<td>

<em>100</em>원

                                                                        <span class="bar">l</span>

<em>1</em>주

                                                                </td>

</tr>

</table> <table class="lwidth" summary="외국인한도주식수 정보">

<caption>외국인한도주식수</caption>

<tr>

<th scope="row">외국인한도주식수(A)</th>

<td><em>5,969,782,550</em></td>

</tr>

<tr>

<th scope="row">외국인보유주식수(B)</th>

<td><em>3,025,292,658</em></td>

</tr>

<tr class="strong">

<th scope="row"><strong>외국인소진율(B/A)</strong><a href="javascript:togglePannel('helpPannel0');" onmouseout="hidePannel('helpPannel0');" onmouseover="showPannel('helpPannel0');"><img alt="외국인소진율(B/A) 상세설명" height="11" src="https://ssl.pstatic.net/static/nfinance/2018/10/26/btn_help.png" width="11"/></a>

<div class="lyr_section">

<div class="tooltip_lyr" id="helpPannel0" style="display:none">

<p>외국인(한도)소진율이란 외국인보유주식수를 외국인한도주식수으로 나눈 값입니다.</p>

<p>일반적인 경우에는 외국인한도주식수와 상장주식수가 같아서 외국인 소진율과 보유율이 동일하지만, 국가 기간산업의 경우 한도주식수가 정해져 있어 두 비율이 달라질 수 있습니다.(Ex. 한국전력)</p>

<span class="arrow"></span>

</div>

</div>

</th>

<td><em>50.68%</em></td>

</tr>

</table> <table class="rwidth" summary="투자의견 정보">

<caption>투자의견</caption>

<tr><th scope="row" style="width:115px">투자의견<span class="bar">l</span>목표주가</th>

<td style="width:115px">

<span class="f_up"><em>4.00</em>매수</span>

<span class="bar">l</span>

<em>77,571</em>

</td></tr>

<tr>

<th scope="row">52주최고<span class="bar">l</span>최저

 

                                                        </th>

<td>

<em>71,800</em>

<span class="bar">l</span>

<em>51,800</em>

</td>

</tr>

</table> <table class="per_table" summary="PER/EPS 정보">

<caption>PER/EPS</caption>

<tbody>

<tr>

<th scope="row">

                                                                        PER<span class="bar">l</span>EPS<span class="date">(2022.12)</span><a href="javascript:togglePannel('helpPannel1');" onmouseout="hidePannel('helpPannel1');" onmouseover="showPannel('helpPannel1');"><img alt="추정PER EPS 상세설명" height="11" src="https://ssl.pstatic.net/static/nfinance/2018/10/26/btn_help.png" width="11"/></a>

<div class="lyr_section">

<div class="tooltip_lyr" id="helpPannel1" style="display:none">

<p>

<strong>PER = 현재가 ÷ EPS</strong>

 

EPS는 지배기업귀속 최근 4분기 합산 순이익을

 

수정평균발행주식수로 나눈 값이며, 보통주와

 

우선주를 합산해서 계산합니다.

                                                                                                                                                                                                                                                   </p>

<span class="arrow"></span>

</div>

</div>

</th>

<td>

<em id="_per">7.37</em>배

 

                                                                        <span class="bar">l</span>

<em id="_eps">8,057</em>원

 

                                                                </td>

</tr>

</tbody>

<tr>

<th scope="row">추정PER<span class="bar">l</span>EPS<a href="javascript:togglePannel('helpPannel3');" onmouseout="hidePannel('helpPannel3');" onmouseover="showPannel('helpPannel3');"><img alt="추정PER EPS 상세설명" height="11" src="https://ssl.pstatic.net/static/nfinance/2018/10/26/btn_help.png" width="11"/></a>

<div class="lyr_section">

<div class="tooltip_lyr tooltip_lyr2" id="helpPannel3" style="display:none">

<p>

<strong>추정PER = 현재가÷추정EPS</strong>

 

추정EPS는 올해 예상EPS에 대한 증권사 추정 평균값(컨센서스)으로 에프앤가이드에서 제공합니다. 추정 증권사가 3개 이상인 경우에만 제공합니다.

                                                                                                                                                                                                                                                   </p>

<span class="arrow"></span>

</div>

</div>

</th>

<td>

<em id="_cns_per">27.00</em>배

 

                                                                        <span class="bar">l</span>

<em id="_cns_eps">2,204</em>원

 

                                                                </td>

</tr>

<tr>

<th scope="row">PBR<span class="bar">l</span>BPS <span class="date">(2022.12)</span><a href="javascript:togglePannel('helpPannel4');" onmouseout="hidePannel('helpPannel4');" onmouseover="showPannel('helpPannel4');"><img alt="PBR | BPS 상세설명" height="11" src="https://ssl.pstatic.net/static/nfinance/2018/10/26/btn_help.png" width="11"/></a>

<div class="lyr_section">

<div class="tooltip_lyr tooltip_lyr3" id="helpPannel4" style="display:none">

<p>

<strong>PBR= 현재가 ÷ BPS</strong>

 

BPS는 최근 분기 자본총계를 수정기말유통주식수로

 

나눈 값이며, 보통주와 우선주를 합산해서 계산합니다.

                                                                                                                                                                                                                                                   </p>

<span class="arrow"></span>

</div>

</div>

</th>

<td>

<em id="_pbr">1.17</em>배

 

                                                                        <span class="bar">l</span>

<em>50,817</em>원

 

                                                                </td>

</tr>

<tr>

<th scope="row">배당수익률<span class="bar">l</span><span>2022.12</span><a href="javascript:togglePannel('helpPannel5');" onmouseout="hidePannel('helpPannel5');" onmouseover="showPannel('helpPannel5');"><img alt="배당수익률 상세설명" height="11" src="https://ssl.pstatic.net/static/nfinance/2018/10/26/btn_help.png" width="11"/></a>

<div class="lyr_section">

<div class="tooltip_lyr dividend_layer" id="helpPannel5" style="display:none">

<strong>배당수익률 = (배당금 / 현재가) x 100</strong>

<p>배당금은 최근 결산연도 기준의 중간배당을 포함한 총 배당금입니다.</p>

<span class="arrow"></span>

</div>

</div>

</th>

<td>

<em id="_dvr">2.43</em>%

 

                                                                </td>

</tr>

</table> <table summary="동일업종 PER 정보">

<caption>동일업종 PER</caption>

<tr class="strong">

<th scope="row"><a class="link_site" href="/sise/sise_group_detail.naver?type=upjong&amp;no=278" onclick="clickcr(this, 'sop.19', '', '2', event)">동일업종 PER</a></th>

<td>

<em>8.99</em>배

 

                                                                </td>

</tr>

<tr>

<th scope="row"><a class="link_site" href="/sise/sise_group_detail.naver?type=upjong&amp;no=278" onclick="clickcr(this, 'sop.19', '', '3', event)">동일업종 등락률</a></th>

<td class="f_down"><em>

                                -1.54%

                                </em></td>

</tr>

</table>

PS C:\Users\Administrator> 

 

 

 

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

?
  • ?
    nanumi 2023.03.24 08:14
    https://docs.google.com/spreadsheets/d/1zL4ONkuOHCc3rkRimTvHviRtm5Kn3mh5_ZhB-dLraDQ/edit?usp=drivesdk

List of Articles
번호 분류 제목 날짜 조회 수
56 파이썬 파이썬 변수전달하기 2021.09.05 1446
55 파이썬 키움증권 OpenAPI 당황스러움 file 2021.09.06 1749
54 파이썬 파이썬 매수할 피라미드 매수전략 2021.09.06 1853
53 파이썬 파이썬 any, all 사용하기(배열데이터 안에 값이 하나라도 있는지 또는 모두 있는지 비교) 2021.09.11 1956
» 파이썬 네이버 주식에서 종목의 투자정보 자료 가져오기 1 2023.03.10 2244
51 파이썬 파이썬 키움증권 open api 분할매매 주문하기 2021.09.07 2338
50 파이썬 python class def 2023.03.04 2366
49 파이썬 파이썬 dictionary 딕셔너리 조작 2021.09.13 2536
48 파이썬 파이썬 키움openAPI 보유종목 종목리스트 피라미드 매도주문하기 2021.09.16 2557
47 파이썬 파이썬 openyxl 엑셀파일(xlsx) 저장하기 2021.09.11 2596
46 파이썬 파이썬 datetime 모듈로 초간단 날짜 표현하기 2021.09.11 2714
45 파이썬 파이썬 변수내용 문자열 자르기 특이한 점 2021.09.27 2965
44 파이썬 파이썬 키움openAPI 보유종목 종목리스트 피라미드 매수주문하기 2021.09.16 3026
43 파이썬 python html tag 제거 경로 금지 문자 제거 2021.10.26 3180
42 파이썬 파이썬 정규표현식 (Regular Expressions) 2021.10.31 3180
41 파이썬 python 에서 구글 캘린더 api 이용하기(server to server) 2021.09.17 3277
40 파이썬 네이버 주식의 기업정보와 펀더멘탈정보 소스 가져오기 2023.03.10 3366
39 파이썬 Python 메타블로그 글쓰기(제로보드, xpressengine blog api) 2021.09.18 3433
38 파이썬 파이썬 팍스넷 추천종목 특정페이지 크롤링 2021.09.23 3466
37 파이썬 키움증권 openAPI 지정가분할매수주문.py 2021.09.13 3527
Board Pagination Prev 1 2 3 Next
/ 3

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소