本文介绍了VB.Net Webview2 如何获取 html 源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我成功地在我的 VB.net (Visual Studio 2017) 项目中的 WebView2 上显示了一个网站,但无法获取 html 源代码.请告诉我如何获取 html 代码.
I sucessfully display a web site on WebView2 in my VB.net (Visual Studio 2017) project but can not get html souce code. Please advise me how to get html code.
我的代码:
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
确实提前感谢您的建议.
Thank you indeed for your advise in advance.
推荐答案
我今天早些时候也刚刚开始使用 WebView2,只是在寻找同样的东西.我确实设法拼凑了这个解决方案:
I've only just started messing with the WebView2 earlier today as well, and was just looking for this same thing. I did manage to scrape together this solution:
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,所以希望不会遗漏任何语法错误.
Converted my code from C# to VB on the fly, so hopefully didn't miss any syntax errors.
这篇关于VB.Net Webview2 如何获取 html 源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!