【发布时间】:2019-10-17 15:55:47
【问题描述】:
我正在尝试抓取网站 (https://na.op.gg/champion/statistics) 以使用 xpath 获取哪些冠军的胜率最高,我可以使用它来做到这一点:
champion = tree.xpath('//div[@class="champion-index-table__name"]/text()')
但是,我意识到我想要获取的名称位于一张表上,该表的大小会根据当前游戏元数据而变化,所以我只想抓取属于特定类别的名称,所以我不会有任何当表中的冠军数量发生变化时,稍后会出现问题。该网站将它们分别放在不同的“层”下,如下所示:
<tbody class="tabItem champion-trend-tier-TOP" style="display: table-row-group;">
<tr>
<td class="champion-index-table__cell champion-index-table__cell--rank">1</td>
<td class="champion-index-table__cell champion-index-table__cell--change champion-index-table__cell--change--stay">
<img src="//opgg-static.akamaized.net/images/site/champion/icon-championtier-stay.png" alt="">
0
</td>
<td class="champion-index-table__cell champion-index-table__cell--image">
<a href="/champion/garen/statistics/top"><i class="__sprite __spc32 __spc32-32"></i></a>
</td>
<td class="champion-index-table__cell champion-index-table__cell--champion">
<a href="/champion/garen/statistics/top">
<div class="champion-index-table__name">Garen</div>
<div class="champion-index-table__position">
Top, Middle </div>
</a>
</td>
<td class="champion-index-table__cell champion-index-table__cell--value">53.12%</td>
<td class="champion-index-table__cell champion-index-table__cell--value">16.96%</td>
<td class="champion-index-table__cell champion-index-table__cell--value">
<img src="//opgg-static.akamaized.net/images/site/champion/icon-champtier-1.png" alt="">
</td>
</tr>
<tr>
然后下一个去
<tbody class="tabItem champion-trend-tier-JUNGLE" style="display: table-row-group;">
所以,我已经尝试过了,但它除了 [] 什么都没有输出。 希望我的问题是有道理的。
championtop = tree.xpath('//div/table/tbody/tr//td[4][@class="champion-index-table__name"]/text()')
【问题讨论】: