0
如何在浏览器控件的窗体中的文本区域中获取文本?有没有办法?从浏览器控件vb.net获取textarea命名输入中的文本
如何在浏览器控件的窗体中的文本区域中获取文本?有没有办法?从浏览器控件vb.net获取textarea命名输入中的文本
(注:我假设你的意思WebBrowser控件)。
你需要步行文档的DOM的控制。您必须开始加载控件,然后在加载后查询DOM。这里是一个例子:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf DocumentCompletedHandler)
WebBrowser1.Navigate("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea")
End Sub
Private Sub DocumentCompletedHandler(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
' Walk the DOM of the document (any time needed after the document has been loaded)
Dim element As HtmlElement
For Each element In WebBrowser1.Document.GetElementsByTagName("textarea")
' Limit our text area to the one with class="code_input".
' You can change this to any other attribute that makes sense:
If element.GetAttribute("className") = "code_input" Then
Console.WriteLine(element.InnerText)
End If
Next
End Sub
End Class