VB.net获取html的参数值

时间:2016-04-26 02:07:01

标签: html vb.net

您好我正在努力从HTML文件中获取一些值。我尝试使用htmlagility,但它似乎无法识别我正在寻找的值。以下是内容示例:



<td pvalue="9" columnid="presentation" role="gridCell" class="dgrid-cell dgrid-cell-padding dgrid-column-0-0 field-ResourceIAQStats nPresentedContacts">9</td><td pvalue="8" columnid="presentation" role="gridCell" class="dgrid-cell dgrid-cell-padding dgrid-column-0-1 field-ResourceIAQStats nHandledContacts">8</td>
&#13;
&#13;
&#13;

我想获得pvalue下的值。这是我的初始代码。我试图使用ReadAllText函数。我知道如果我做得不对。任何帮助将不胜感激。

        Dim text As String = File.ReadAllText("D:\Downloads\ifr.htm")
        Dim searchtxt As String = "field-ResourceIAQStats avgTalkDuration"">"
        Dim index As Integer = text.IndexOf(searchtxt)
        If index >= 0 Then
            MsgBox(Microsoft.VisualBasic.(text.Substring(index)))
        End If

修改

我将此代码用于XML / XPath查询。

        Dim nav As XPathNavigator
        Dim docNav As XPathDocument
        Dim NodeIter As XPathNodeIterator
        Dim strExpression As String

        'Open the XML.
        docNav = New XPathDocument("D:\Downloads\ifr.htm")

        'Create a navigator to query with XPath.
        nav = docNav.CreateNavigator

        strExpression = "//td[@class='dgrid-cell dgrid-cell-padding dgrid-column-0-3 field-ResourceIAQStats longestTalkDuration'"
        NodeIter = nav.Select(strExpression)
        MsgBox(NodeIter.Current.Value)

0 个答案:

没有答案