작성
·
706
답변 2
0
table에 담겨 있는 값은 아래와 같습니다.
저는 jupitor notebook 쓰는데 jupitor notebook에서는 type(table)하면 bs4.element.ResultSet라고 뜹니다.
위에서 첨부해주신 colab에서는 jopitor notebook의 코드 그대로 복사해서 실행하면 type(table)이 list라고 잘 뜹니다.
[<table cellspacing="0" class="type2"> <tr> <th>날짜</th> <th>종가</th> <th>전일비</th> <th>시가</th> <th>고가</th> <th>저가</th> <th>거래량</th> </tr> <tr> <td colspan="7" height="8"></td> </tr> <tr onmouseout="mouseOut(this)" onmouseover="mouseOver(this)"> <td align="center"><span class="tah p10 gray03">2021.05.20</span></td> <td class="num"><span class="tah p11">113,000</span></td> <td class="num"> <span class="tah p11">0</span> </td> <td class="num"><span class="tah p11">113,000</span></td> <td class="num"><span class="tah p11">113,000</span></td> <td class="num"><span class="tah p11">113,000</span></td> <td class="num"><span class="tah p11">0</span></td> </tr> <tr onmouseout="mouseOut(this)" onmouseover="mouseOver(this)"> <td align="center"><span class="tah p10 gray03">2021.05.18</span></td> <td class="num"><span class="tah p11">113,000</span></td> <td class="num"> <img alt="상승" height="6" src="https://ssl.pstatic.net/imgstock/images/images4/ico_up.gif" style="margin-right:4px;" width="7"/><span class="tah p11 red02"> 2,000 </span> </td> <td class="num"><span class="tah p11">112,000</span></td> <td class="num"><span class="tah p11">113,000</span></td> <td class="num"><span class="tah p11">110,500</span></td> <td class="num"><span class="tah p11">223,112</span></td> </tr> <tr onmouseout="mouseOut(this)" onmouseover="mouseOver(this)"> <td align="center"><span class="tah p10 gray03">2021.05.17</span></td> <td class="num"><span class="tah p11">111,000</span></td> <td class="num"> <img alt="상승" height="6" src="https://ssl.pstatic.net/imgstock/images/images4/ico_up.gif" style="margin-right:4px;" width="7"/><span class="tah p11 red02"> 500 </span> </td> <td class="num"><span class="tah p11">111,500</span></td> <td class="num"><span class="tah p11">114,000</span></td> <td class="num"><span class="tah p11">110,000</span></td> <td class="num"><span class="tah p11">352,455</span></td> </tr> <tr onmouseout="mouseOut(this)" onmouseover="mouseOver(this)"> <td align="center"><span class="tah p10 gray03">2021.05.14</span></td> <td class="num"><span class="tah p11">110,500</span></td> <td class="num"> <img alt="상승" height="6" src="https://ssl.pstatic.net/imgstock/images/images4/ico_up.gif" style="margin-right:4px;" width="7"/><span class="tah p11 red02"> 2,500 </span> </td> <td class="num"><span class="tah p11">108,500</span></td> <td class="num"><span class="tah p11">112,000</span></td> <td class="num"><span class="tah p11">108,500</span></td> <td class="num"><span class="tah p11">225,513</span></td> </tr> <tr onmouseout="mouseOut(this)" onmouseover="mouseOver(this)"> <td align="center"><span class="tah p10 gray03">2021.05.13</span></td> <td class="num"><span class="tah p11">108,000</span></td> <td class="num"> <img alt="상승" height="6" src="https://ssl.pstatic.net/imgstock/images/images4/ico_up.gif" style="margin-right:4px;" width="7"/><span class="tah p11 red02"> 500 </span> </td> <td class="num"><span class="tah p11">106,500</span></td> <td class="num"><span class="tah p11">109,000</span></td> <td class="num"><span class="tah p11">105,000</span></td> <td class="num"><span class="tah p11">303,192</span></td> </tr> <tr> <td colspan="7" height="8"></td> </tr> <tr> <td bgcolor="#e1e1e1" colspan="7" height="1"></td> </tr> <tr> <td colspan="7" height="8"></td> </tr> <tr onmouseout="mouseOut(this)" onmouseover="mouseOver(this)"> <td align="center"><span class="tah p10 gray03">2021.05.12</span></td> <td class="num"><span class="tah p11">107,500</span></td> <td class="num"> <img alt="상승" height="6" src="https://ssl.pstatic.net/imgstock/images/images4/ico_up.gif" style="margin-right:4px;" width="7"/><span class="tah p11 red02"> 1,000 </span> </td> <td class="num"><span class="tah p11">108,000</span></td> <td class="num"><span class="tah p11">114,500</span></td> <td class="num"><span class="tah p11">107,000</span></td> <td class="num"><span class="tah p11">860,584</span></td> </tr> <tr onmouseout="mouseOut(this)" onmouseover="mouseOver(this)"> <td align="center"><span class="tah p10 gray03">2021.05.11</span></td> <td class="num"><span class="tah p11">106,500</span></td> <td class="num"> <img alt="하락" height="6" src="https://ssl.pstatic.net/imgstock/images/images4/ico_down.gif" style="margin-right:4px;" width="7"/><span class="tah p11 nv01"> 3,000 </span> </td> <td class="num"><span class="tah p11">109,000</span></td> <td class="num"><span class="tah p11">109,000</span></td> <td class="num"><span class="tah p11">106,000</span></td> <td class="num"><span class="tah p11">210,598</span></td> </tr> <tr onmouseout="mouseOut(this)" onmouseover="mouseOver(this)"> <td align="center"><span class="tah p10 gray03">2021.05.10</span></td> <td class="num"><span class="tah p11">109,500</span></td> <td class="num"> <img alt="상승" height="6" src="https://ssl.pstatic.net/imgstock/images/images4/ico_up.gif" style="margin-right:4px;" width="7"/><span class="tah p11 red02"> 1,500 </span> </td> <td class="num"><span class="tah p11">108,500</span></td> <td class="num"><span class="tah p11">110,000</span></td> <td class="num"><span class="tah p11">107,500</span></td> <td class="num"><span class="tah p11">212,041</span></td> </tr> <tr onmouseout="mouseOut(this)" onmouseover="mouseOver(this)"> <td align="center"><span class="tah p10 gray03">2021.05.07</span></td> <td class="num"><span class="tah p11">108,000</span></td> <td class="num"> <img alt="상승" height="6" src="https://ssl.pstatic.net/imgstock/images/images4/ico_up.gif" style="margin-right:4px;" width="7"/><span class="tah p11 red02"> 2,000 </span> </td> <td class="num"><span class="tah p11">106,500</span></td> <td class="num"><span class="tah p11">108,500</span></td> <td class="num"><span class="tah p11">106,000</span></td> <td class="num"><span class="tah p11">174,741</span></td> </tr> <tr onmouseout="mouseOut(this)" onmouseover="mouseOver(this)"> <td align="center"><span class="tah p10 gray03">2021.05.06</span></td> <td class="num"><span class="tah p11">106,000</span></td> <td class="num"> <img alt="상승" height="6" src="https://ssl.pstatic.net/imgstock/images/images4/ico_up.gif" style="margin-right:4px;" width="7"/><span class="tah p11 red02"> 1,500 </span> </td> <td class="num"><span class="tah p11">104,000</span></td> <td class="num"><span class="tah p11">107,500</span></td> <td class="num"><span class="tah p11">103,500</span></td> <td class="num"><span class="tah p11">264,179</span></td> </tr> <tr> <td colspan="7" height="8"></td> </tr> </table>, <table align="center" class="Nnavi" summary="페이지 네비게이션 리스트"> <caption>페이지 네비게이션</caption> <tr> <td class="on"> <a href="/item/sise_day.nhn?code=326030&page=1">1</a> </td> <td> <a href="/item/sise_day.nhn?code=326030&page=2">2</a> </td> <td> <a href="/item/sise_day.nhn?code=326030&page=3">3</a> </td> <td> <a href="/item/sise_day.nhn?code=326030&page=4">4</a> </td> <td> <a href="/item/sise_day.nhn?code=326030&page=5">5</a> </td> <td> <a href="/item/sise_day.nhn?code=326030&page=6">6</a> </td> <td> <a href="/item/sise_day.nhn?code=326030&page=7">7</a> </td> <td> <a href="/item/sise_day.nhn?code=326030&page=8">8</a> </td> <td> <a href="/item/sise_day.nhn?code=326030&page=9">9</a> </td> <td> <a href="/item/sise_day.nhn?code=326030&page=10">10</a> </td> <td class="pgR"> <a href="/item/sise_day.nhn?code=326030&page=11"> 다음<img alt="" border="0" height="5" src="https://ssl.pstatic.net/static/n/cmn/bu_pgarR.gif" width="3"/> </a> </td> <td class="pgRR"> <a href="/item/sise_day.nhn?code=326030&page=22">맨뒤 <img alt="" border="0" height="5" src="https://ssl.pstatic.net/static/n/cmn/bu_pgarRR.gif" width="8"/> </a> </td> </tr> </table>]
0
안녕하세요.
table 에 어떤 값이 들어있는지 확인을 해보세요.
table을 출력했을 때 대괄호로 [] 값이 감싸져 있는지 확인해 보세요.
또, 아래 링크를 통해 해당 실습을 실행해 보실 수 있는데요.
SK바이오팜으로 되어있으니 직접 실행해 보시면서 차이를 비교해 보세요.
또, 직접했을 때 잘 안 되시면 table에 담겨있는 값과 해당 코드 출력 전 실행한 윗부분의 코드 스크린샷을 올려주시면 도움을 드릴게요!
안녕하세요.
출력된 모습을 보면 데이터를 잘 가져온 것으로 보여집니다.
타입이 다르게 나오는 이유는 뷰티플숩의 버전이나 파이썬 버전에 따라 다르게 출력을 할 수 있습니다.
colab에서는 아래와 같은 버전을 사용하고 있습니다. 아마도 로컬 주피터 노트북은 다른 버전을 사용하고 있으실거에요.
여기에서 type을 출력해 본 이유는 [] 형태로 감싸져 있기 때문에 타입을 확인해 보고 인덱싱을 해서 값을 가져올 수 있겠다를 보기 위함이었었요.
jinhijinhi 님께서 현재 사용하고 있는 버전의 타입이 좀 더 정확한 타입으로 보여집니다.
그래서 [ ] 로 감싸져 있는 값이라면 인덱싱과 슬라이싱이 가능합니다.
이를 활용해서 데이터를 다루시면 될것 같아요.
참고로 인덱싱은 인덱스 순서번호로 데이터를 가져오는 것이고 (파이썬은 0부터 시작합니다.)
슬라이싱은 데이터를 나눌때 사용합니다. [시작인덱스:끝나는인덱스+1] 로 사용하시면 됩니다.