【发布时间】:2014-09-29 15:17:30
【问题描述】:
我需要解析一个格式如下的html表格:
require 'nokogiri'
html_table = '<table>
<tbody>
<tr>
<td>Some text in the first row!</td>
<td>More text in the first row!</td>
</tr>
<td>Some text in the second row!</td>
<td>More text in the second row!</td> </tr>
<td>Some text in the third row!</td>
<td>More text in the third row!</td> </tr>
</tbody>
</table>'
如您所见,最后两行没有打开的<tr> 标记。当我尝试使用puts Nokogiri::HTML(html_table).css('table tr') 获取所有三行时,代码被清除,最后两行变为td 节点:
<tr>
<td>Some text in the first row!</td>
<td>More text in the first row!</td>
</tr>
当没有结束标签</tr> 时,我在网上找到了一些解决此问题的方法,但反之则不行。
有没有使用 Nokogiri 解决此问题的简单方法?
【问题讨论】: