将节点的内部文本添加到List或Array

时间:2017-09-13 09:57:10

标签: vb.net

我使用HtmlAgilityPack来解析我的路由器的网络配置菜单。我使用此代码来获取表格单元格中的数据。如何将结果添加到ListArray。这是代码:

Public Sub TestFunction()
        Dim htmldoc As New HtmlDocument
        htmldoc.LoadHtml(SendRequest())
        Dim nodes As HtmlNodeCollection = htmldoc.DocumentNode.SelectNodes("//table/tr/tr")

        For Each trs In nodes
            For Each tds In trs.ChildNodes
                Debug.WriteLine(tds.InnerText)'add this output to list or array
            Next
            Debug.WriteLine(" ")
        Next
End Sub

它的外观如下:

cc:c7:60:79:8c:e9
11921
18509
130
yes
150

2c:d0:5a:47:0a:86
3819722
1917451
81
no
150

我希望这些数据在数组或其他内容中看起来像这个结构

 0 => {
 datahere
 datahere
 datahere
},
1 => {
 datahere
 datahere
 datahere
}

解决方案:我知道这是粗糙的,但还有更好的方法吗?

Public Sub TestFunction()
        Dim htmldoc As New HtmlDocument
        htmldoc.LoadHtml(SendRequest())
        Dim nodes As HtmlNodeCollection = htmldoc.DocumentNode.SelectNodes("//table/tr/tr")
        Dim values As New List(Of List(Of String))
        For Each trs In nodes
            Dim lst As New List(Of String)
            For Each tds In trs.ChildNodes
                lst.Add(tds.InnerText)
            Next
            values.Add(lst)
            Debug.WriteLine("")
        Next
        Debug.WriteLine(values.Item(0).Item(0))
    End Sub

0 个答案:

没有答案