尝试弄清楚如何从此网页中提取数据并将其放入.csv。档案:https://www.basketball-reference.com/draft/BAA_1947.html
每行的表结构如下图所示:
<tr data-row="12">
<th scope="row" class="right " data-stat="ranker" >11</th>
<td class="left " data-stat="player" csk="Bolyard,Robert" >Robert Bolyard</td>
<td class="left " data-stat="college_name" csk="University of Toledo" ><a href="/friv/draft.fcgi?college=toledo">University of Toledo</a></td>
<td class="right " data-stat="seasons" >12</td>
</tr>
我想知道抓取文本的Xpath值。
到目前为止,我有以下内容:
# Xpath
player = data.xpath("//td/span[@data-stat='player']/text()")
college = data.xpath("//td/span[@data-stat='college_name']/a/text()")
seasons = data.xpath("//td/span[@data-stat='seasons']/text()")
问题是它不会将任何值返回到任何列。 Xpath语句可能有什么问题?
答案 0 :(得分:0)
您正在寻找td
内的player = data.xpath("//td[@data-stat='player']/text()")
college = data.xpath("//td[@data-stat='college_name']/a/text()")
seasons = data.xpath("//td[@data-stat='seasons']/text()")
,但没有。{/ p>
如果删除xpath的那部分,它将起作用:
$(document).ready(function () {
var $grid = $('.grid').masonry({
itemSelector: '.col-override',
horizontalOrder: true,
transitionDuration: '0.8s',
});
$grid.on('click', '.card', function () {
$(this).toggleClass('open');
$(this).find('.card-header .card-tools .btn.card-toggle i').toggleClass('openState');
// trigger layout after item size changes
$grid.masonry('layout');
});
});