BeautifulSoupでtdタグでとクラスで絞って抽出したのですが、なぜかHPの表示と順番がずれてしまいます。
どなたかわかるかたがいたらご教示ください。
python
1 url = "https://dt.kabumap.com/servlets/dt/Action?SRC=change/base" 2 html = requests.get(url) 3 html.encoding = html.apparent_encoding 4 soup = BeautifulSoup(html.text, 'html.parser') 5 table = soup.find_all("td", attrs={"class": "onlyPc fontS"}) 6
下から2番目と3番目が逆になってしまう。
[<td class="onlyPc fontS"><span>JQS</span></td>, <td class="onlyPc fontS"><span>制度</span></td>, <td class="onlyPc fontS"><span>JQS</span></td>, <td class="onlyPc fontS"><span>制度</span></td>, <td class="onlyPc fontS"><span>東マ</span></td>, <td class="onlyPc fontS"><span>制度</span></td>, <td class="onlyPc fontS"><span>東マ</span></td>, <td class="onlyPc fontS"><span>制度</span></td>, <td class="onlyPc fontS"><span>東2</span></td>, <td class="onlyPc fontS"><span>制度</span></td>, <td class="onlyPc fontS"><span>JQS</span></td>, <td class="onlyPc fontS"><span>貸借</span></td>, <td class="onlyPc fontS"><span>東マ</span></td>, <td class="onlyPc fontS"><span>制度</span></td>, <td class="onlyPc fontS"><span>東2</span></td>, <td class="onlyPc fontS"><span>制度</span></td>, <td class="onlyPc fontS"><span>東1</span></td>, <td class="onlyPc fontS"><span>貸借</span></td>, <td class="onlyPc fontS"><span>東1</span></td>, <td class="onlyPc fontS"><span>制度</span></td>, <td class="onlyPc fontS"><span>JQG</span></td>, <td class="onlyPc fontS"><span>制度</span></td>, <td class="onlyPc fontS"><span>東1</span></td>, <td class="onlyPc fontS"><span>貸借</span></td>, <td class="onlyPc fontS"><span>札証</span></td>, <td class="onlyPc fontS"><span></span></td>, ←ここの札証と上の東1の順番が逆になっている。 <td class="onlyPc fontS"><span>東2</span></td>, <td class="onlyPc fontS"><span>制度</span></td>,
HTML
1 2<td class="figure">12</td> 3<td class="onlyTbPc"><a href="Action?SRC=basic/base&codetext=2928" target="_blank">2928</a></td> 4<td><div class="chartWrap fontS"><a onmouseover="javascript:showChart('2928');" onmouseout="javascript:hideChart('2928');"href="Action?SRC=basic/base&codetext=2928">RIZAPグループ</a><div id="chart2928" class="popChart"><img src="cgi-bin/picoLight/pl.pl?2928,210,100,5c1d3a9b7425f22e83d506858d85be0720743850,156.0" width="210" height="100" /></div></div></td> 5<td class="onlyPc fontS"><span>札証</span></td> 6<td class="onlyPc fontS"><span></span></td> 7<td class="onlySp">09/18<br>15:30</td> 8<td class="onlyTbPc">09/18</td> 9<td class="onlyTbPc">15:30</td> 10<td class="figure onlyTbPc">168.0</td> 11<td class="figure up onlyTbPc">+12.0</td> 12<td class="figure up onlyTbPc">+7.69</td> 13<td class="figure onlyPc">823,900</td> 14<td class="emp figure up">+8.39</td> 15<td class="figure onlyPc">85</td> 16<td class="figure onlyPc">93</td> 17<td class="figure onlyPc">56.42</td></tr> 18<tr><td class="figure">13</td> 19<td class="onlyTbPc"><a href="Action?SRC=basic/base&codetext=7014" target="_blank">7014</a></td> 20<td><div class="chartWrap fontS"><a onmouseover="javascript:showChart('7014');" onmouseout="javascript:hideChart('7014');"href="Action?SRC=basic/base&codetext=7014">名村造船所</a><div id="chart7014" class="popChart"><img src="cgi-bin/picoLight/pl.pl?7014,210,100,5c1d3a9b7425f22e83d506858d85be0720743850,156.0" width="210" height="100" /></div></div></td> 21<td class="onlyPc fontS"><span>東1</span></td> 22<td class="onlyPc fontS"><span>貸借</span></td> 23<td class="onlySp">09/18<br>15:00</td> 24<td class="onlyTbPc">09/18</td><td class="onlyTbPc">15:00</td> 25<td class="figure onlyTbPc">168.0</td> 26<td class="figure up onlyTbPc">+12.0</td> 27<td class="figure up onlyTbPc">+7.69</td> 28<td class="figure onlyPc">1,118,400</td> 29<td class="emp figure up">+8.39</td> 30<td class="figure onlyPc">50</td> 31<td class="figure onlyPc">12</td> 32<td class="figure onlyPc">45.63</td></tr> 33
あなたの回答
tips
プレビュー