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