试图获取输入/getelementbyID或Class并放入richtextbox [英] Trying to get inputs / getelementbyID or Class and put into richtextbox
本文介绍了试图获取输入/getelementbyID或Class并放入richtextbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用HtmlAgility Pack首先解析一些HTML,用于表单输入标签,然后获取ID或类的名称,并列出输入和id ="something here"或输入:class ="something here"进入RichTextbox进行审核.
I am currently using HtmlAgility Pack to parse some HTML for a forms input tags first, then the get the name of the ID or Class and list the input and the id="something here or input: class="something here" into a RichTextbox to review.
这是我的代码.
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选择字符串是固定的):
Here is how you can do this (note that the SelectNodes selection string was fixed):
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
这篇关于试图获取输入/getelementbyID或Class并放入richtextbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文