gpt4 book ai didi

VB.Net Webview2 如何获取 html 源代码?

转载 作者:行者123 更新时间:2023-12-03 18:32:08 26 4
gpt4 key购买 nike

我成功地在我的 VB.net (Visual Studio 2017) 项目中的 WebView2 上显示了一个网站,但无法获取 html 源代码。请告诉我如何获取 html 代码。

我的代码:

Private Sub testbtn_Click(sender As Object, e As EventArgs) Handles testbtn.Click
WebView2.CoreWebView2.Navigate("https://www.microsoft.com/")
End Sub

Private Sub WebView2_NavigationCompleted(sender As Object, e As CoreWebView2NavigationCompletedEventArgs) Handles WebView2.NavigationCompleted
Dim html As String = ?????
End Sub

确实提前感谢您的建议。

最佳答案

我今天早些时候也刚刚开始弄乱 WebView2,只是在寻找同样的东西。我确实设法拼凑了这个解决方案:

Dim html As String
html = Await WebView2.ExecuteScriptAsync("document.documentElement.outerHTML;")

' The Html comes back with unicode character codes, other escaped characters, and
' wrapped in double quotes, so I'm using this code to clean it up for what I'm doing.
html = Regex.Unescape(html)
html = html.Remove(0, 1)
html = html.Remove(html.Length - 1, 1)

即时将我的代码从 C# 转换为 VB,所以希望不会错过任何语法错误。

关于VB.Net Webview2 如何获取 html 源代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62431464/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com