如何从 Xamarin 表单中的 WebView 获取内部 html 源代码 - C# [英] How to get inner html source from WebView in Xamarin Form - C#
问题描述
我正在使用 WebView 加载我的身份验证网页.身份验证成功后,我需要从 html 源内容中获取一些值.任何人都可以掌舵从 WebView 读取源 html 吗?.
I am using WebView to load my authentication web page. After the successful authentication, I need to get some values from html source content. can anyone helm to read the source html from WebView?.
var webView= new WebView {
Source = "https://www.MyLoginSite.com"
};
我检查了这个线程:Xamarin:如何获得来自 WebView 页面的 HTML?
我在看到上面的线程后编写了下面的代码.
I have written the below code after seeing above thread.
webView.Eval("document.body.innerHTML")
但是 Eval 是 void 函数,那么我如何在 C# 代码隐藏中读取值,或者是否有任何简单的替代方法可以将整个 html 内容作为字符串获取?
But the Eval is the void function, so how can I read value in C# code-behind or is there any easy alternative method to get entire html content as string?
推荐答案
这是我的代码:
private async Task<string> GetHtml()
{
return await LoginWebViewItem.EvaluateJavaScriptAsync("document.body.innerHTML");
}
然后我从我的方法中调用它:
Then I call this from my method:
string AllHtml = await GetHtml();
这篇关于如何从 Xamarin 表单中的 WebView 获取内部 html 源代码 - C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!