Ruby nokogiri正在解析tr中的第一个td忽略特定类
我有下面的htmlRuby nokogiri正在解析tr中的第一个td忽略特定类,ruby,parsing,nokogiri,Ruby,Parsing,Nokogiri,我有下面的html <table> <tr> <th>value</th> <th>description</th> </tr> <tr> <td>OverallHealthScore</td> <td> Overall HealthScore. <
<table>
<tr>
<th>value</th>
<th>description</th>
</tr>
<tr>
<td>OverallHealthScore</td>
<td>
Overall HealthScore.
</td>
</tr>
<tr>
<td class="deprecated">DESTAGED_TRACKS_PER_SEC</td>
<td>
The tracks per second saved into disks.
</td>
</tr>
</table>
让我大致了解,但打印出不推荐项目的“描述”td。我似乎不知道我需要做什么才能得到我需要的结果。假设您想要得到第一个未被否决的td值:
<table>
<tr>
<th>value</th>
<th>description</th>
</tr>
<tr>
<td>OverallHealthScore</td>
<td>
Overall HealthScore.
</td>
</tr>
<tr>
<td class="deprecated">DESTAGED_TRACKS_PER_SEC</td>
<td>
The tracks per second saved into disks.
</td>
</tr>
<tr>
<td>AvaiableAnother</td>
<td>
Another Available HealthScore.
</td>
</tr>
<tr>
<td class="deprecated">OTHER_DEPRE</td>
<td>
The tracks per second saved into disks.
</td>
</tr>
</table>
嘿,你的问题很不清楚。”为了得到我所需要的结果,我需要做什么“几乎不能解释任何事情”。您至少需要共享示例html代码段和您期望的输出。您好,感谢您的评论。我只需要提取总体健康分数,而不是每秒销毁轨道。假设有更多的行没有class=deprected规范,假设有更多的行class=deprected,我想以一个非deprected度量数组作为结束。css('td:first child:not(.deprecated)')。map(&:text)td:eq(1):not(.deprecated)和
td[1]:not(.deprecated)
也可以
<table>
<tr>
<th>value</th>
<th>description</th>
</tr>
<tr>
<td>OverallHealthScore</td>
<td>
Overall HealthScore.
</td>
</tr>
<tr>
<td class="deprecated">DESTAGED_TRACKS_PER_SEC</td>
<td>
The tracks per second saved into disks.
</td>
</tr>
<tr>
<td>AvaiableAnother</td>
<td>
Another Available HealthScore.
</td>
</tr>
<tr>
<td class="deprecated">OTHER_DEPRE</td>
<td>
The tracks per second saved into disks.
</td>
</tr>
</table>
puts table.css('td:first-child:not(.deprecated)').map(&:text)
# OverallHealthScore
# AvaiableAnother