使用HtmlAgility提取跨度内的文本

时间:2017-08-16 08:13:32

标签: vb.net xpath html-agility-pack

要求:提取“无损”文本。

if 2 >= 4:
     print 'most common.'

我只能通过以下方式提取整个文本“4:59Lossless”:

<td nowrap="nowrap" align="center">
<span class="gen">4:59<br /><span style="color: red">Lossless</span></span>
</td>

我也试过

Dim divnodes As HtmlNode = doc.DocumentNode.SelectSingleNode("//td[@nowrap='nowrap']//span[@class='gen']")

        If Not divnodes Is Nothing Then
            MsgBox(div.InnerText)
        End If

但没有工作。

你可以跟我说说谢谢〜

1 个答案:

答案 0 :(得分:0)

我通过添加“/ span”

解决了这个问题
           Dim divnodes As HtmlNodeCollection =doc.DocumentNode.SelectNodes("//td[@nowrap='nowrap']//span[@class='gen']/span")

            If divnodes IsNot Nothing Then
            For each div as HtmlNode in divnodes2
              MsgBox(div.InnerText)
            Next               
            End If