netkeiba.com様から利用させて頂いております、python2.7,beautifulsoupでの競馬情報のスクレイピングが、うまく出来ません。
# -*- coding:utf-8 -*- import urllib2 import codecs import time import random from bs4 import BeautifulSoup url='http://db.netkeiba.com/?pid=bms_leading&year=2017' soup = BeautifulSoup(urllib2.urlopen(url).read(),"lxml") tr_arr1 = soup.select("table.nk_tb_common race_table_01") print tr_arr1
上記のソースコードでは、何も吐き出しません。 soup.select の根拠となった、当サイトのソースコードが下記の通りでございます。
</ul> </div><!-- //class="db_sub_menu" --> <table cellpadding="0" cellspacing="1" summary="リーディング順位" class="nk_tb_common race_table_01"> <tr align="center"> <th rowspan="2" class="hml" nowrap>順位</th> <th rowspan="2" class="hml" nowrap>馬名</th> <th rowspan="2" class="hml" nowrap>出走<br />頭数</th> <th rowspan="2" class="hml" nowrap>勝馬<br />頭数</th> <th rowspan="2" class="hml" nowrap>出走<br />回数</th> <th rowspan="2" class="hml" nowrap>勝利<br />回数</th> <th colspan="2" class="hml" nowrap>重賞</th> <th colspan="2" class="hml" nowrap>特別</th> <th colspan="2" class="hml" nowrap>平場</th> <th colspan="2" class="hml" nowrap>芝</th> <th colspan="2" class="hml" nowrap>ダート</th> <th rowspan="2" class="hml" nowrap>勝馬<br />率</th> <th rowspan="2" class="hml" nowrap>EI</th> <th rowspan="2" class="hml" nowrap>入着賞金<br />(万円)</th> <th rowspan="2" class="hml" nowrap>平均距離<br />(芝)</th> <th rowspan="2" class="hml" nowrap>平均距離<br />(ダ)</th> <th rowspan="2" class="hml" nowrap>代表馬</th> <th rowspan="2" class="hml" nowrap>順位変動</th> </tr> <tr align="center"> <th class="hml" nowrap>出走</th> <th class="hml" nowrap>勝利</th> <th class="hml" nowrap>出走</th> <th class="hml" nowrap>勝利</th> <th class="hml" nowrap>出走</th> <th class="hml" nowrap>勝利</th> <th class="hml" nowrap>出走</th> <th class="hml" nowrap>勝利</th> <th class="hml" nowrap>出走</th> <th class="hml" nowrap>勝利</th> </tr> <tr> <td nowrap>1</td> <td class="txt_l" nowrap><a href="/horse/sire/000a00033a/">サンデーサイレンス</a></td> <td nowrap>517</td> <td nowrap>104</td>
実際の全てのソースコードを御覧いただければ、もっと良いと思いますが、
tr_arr1 = soup.select("table.nk_tb_common race_table_01") の部分は、かなり自信がございましたのに
何も吐き出さないので、苦慮しております。
先輩方の、御教示、よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/25 17:40