javascript - 尝试从 UWP WebView 获取 html 时出现异常(HRESULT 异常:0x80020101)
问题描述
我需要从 WebView 获取 html。我在网上找到了以下代码:
public MainPage()
{
this.InitializeComponent();
WebView wb = new WebView();
wb.Navigate(new Uri(@"https://www.microsoft.com/"));
Thread.Sleep(1500);
F(wb);
}
public async void F(WebView webView)
{
var siteHtML = await webView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });
}
不幸的是,InvokeScriptAsync 方法返回错误,我根本不懂脚本。您还有其他方法可以从 WebView 获取 html,或者您可以修复我的代码吗?
解决方案
尝试从 UWP WebView 获取 html 时出现异常(HRESULT 异常:0x80020101)
问题是 WebView 没有导航完成,对于这种情况,您可以在NavigationCompleted
事件中调用 eval 函数。在测试过程中,它运行良好。
wb.Navigate(new Uri(@"https://www.microsoft.com/"));
wb.NavigationCompleted += Wb_NavigationCompleted;
.....
private async void Wb_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
var siteHtML = await wb.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });
}
推荐阅读
- sql - 使用 CHARINDEX 传递给 RIGHT 函数的长度参数无效
- python - 在尊重日期时间的同时计算滚动分组的乘积
- c++ - 回文字符串问题:为什么我必须放 +1 而不是 -1 才能使这段代码工作?
- java - java - 如何按“/”分割并存储为像java中的树一样分层?
- php - 如何在php中放置php
- php - PHP 变量未填充到表单上的 HTML datetime-local 字段中
- bash - 如何让 Bash 脚本引用本地文件
- xslt - 使用节点和属性上的 group by 从 xml 到 xml 的 xslt 转换
- android - LiveData 和 MVVM 模式
- reactjs - 在 Firestore 和 Firebase Auth 中处理用户数据的最佳方式配置为允许每封电子邮件有多个帐户