.net 尝试获取输入/getelementbyID或类并放入richtextbox

.net 尝试获取输入/getelementbyID或类并放入richtextbox,.net,html-parsing,html-agility-pack,.net,Html Parsing,Html Agility Pack,我目前正在使用Htmlagibility Pack首先解析表单输入标记的一些HTML,然后获取ID或类的名称,并将输入和ID=somethine here或input:Class=somethine here列在RichTextbox中进行查看 这是我的密码 Dim web As HtmlAgilityPack.HtmlWeb = New HtmlWeb() Dim doc As HtmlAgilityPack.HtmlDocument = web.Load(TextBox1.Text) Dim

我目前正在使用Htmlagibility Pack首先解析表单输入标记的一些HTML,然后获取ID或类的名称,并将输入和ID=somethine here或input:Class=somethine here列在RichTextbox中进行查看

这是我的密码

Dim web As HtmlAgilityPack.HtmlWeb = New HtmlWeb()
Dim doc As HtmlAgilityPack.HtmlDocument = web.Load(TextBox1.Text)
Dim threadLinks As IEnumerable(Of HtmlNode) = doc.DocumentNode.SelectNodes("/input")

For Each link In threadLinks
Dim str As String = link.InnerHtml
RichTextBox1.Text = str.ToString

Next link

End Sub

以下是如何执行此操作注意SelectNodes选择字符串已修复:

    Dim threadLinks As IEnumerable(Of HtmlNode) = doc.DocumentNode.SelectNodes("//input")

    ' Use a stringbuilder to hold all of the retrieved information
    Dim sbText As New System.Text.StringBuilder(5000)

    If threadLinks IsNot Nothing Then
        For Each link In threadLinks
            ' Add information about each found input on a new line
            sbText.Append("Id = ").Append(link.Id)

            ' The class is held in an attribute, so ensure the attribute exists before using it
            If link.Attributes.Contains("Class") Then
                ' Add the value of the class attribute to the output
                sbText.Append(", Class = ").Append(link.Attributes("Class").Value)
            End If

            ' Separate this item from the next by adding a new line
            sbText.AppendLine()
        Next
    End If

    ' Finally, send the retrieved information to the textbox.
    RichTextBox1.Text = sbText.ToString