vb.net - 抓取 web 视图中显示的文本输入框的值并将其带回 winforms
vb.net - grabbing the value ot a text input box displayed in a webview and bringing it back into winforms
我有一个包含 webview 的 winform。
在某些时候,网络视图会显示 html 内容,包括供最终用户输入一些响应的输入框。
我是否可以与 webview 中的输入框交互以编程方式获取其内容?
即使只是在消息框中显示该文本作为示例,这也会让我顺利进行!
所以在下面的示例表单中,我希望获取最终用户输入 'userresponse' 的任何内容并将其放入变量中。喜欢...
dim response as string = 'the contents of the input box in the webview
messagebox.show(response)
感谢任何帮助并提前致谢! :)
<HTML>
<Body>
<form>
<input type="text" id="userresponse" name="userresponse"><br>
</form>
</Body>
</HTML>
您可以使用 InvokeScriptAsync() 来实现它。
示例代码:
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim html As String = File.ReadAllText("test1.html")
WebView1.NavigateToString(html)
End Sub
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ss As String = Await WebView1.InvokeScriptAsync("eval", New String() {"document.getElementById('userresponse').value;"})
MsgBox(ss)
End Sub
End Class
结果:
我有一个包含 webview 的 winform。 在某些时候,网络视图会显示 html 内容,包括供最终用户输入一些响应的输入框。
我是否可以与 webview 中的输入框交互以编程方式获取其内容? 即使只是在消息框中显示该文本作为示例,这也会让我顺利进行!
所以在下面的示例表单中,我希望获取最终用户输入 'userresponse' 的任何内容并将其放入变量中。喜欢...
dim response as string = 'the contents of the input box in the webview
messagebox.show(response)
感谢任何帮助并提前致谢! :)
<HTML>
<Body>
<form>
<input type="text" id="userresponse" name="userresponse"><br>
</form>
</Body>
</HTML>
您可以使用 InvokeScriptAsync() 来实现它。
示例代码:
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim html As String = File.ReadAllText("test1.html")
WebView1.NavigateToString(html)
End Sub
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ss As String = Await WebView1.InvokeScriptAsync("eval", New String() {"document.getElementById('userresponse').value;"})
MsgBox(ss)
End Sub
End Class
结果: