如何以Xamarin形式从WebView获取内部html源-C# [英] How to get inner html source from WebView in Xamarin Form - C#

查看:305
本文介绍了如何以Xamarin形式从WebView获取内部html源-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 checked this thread : Xamarin: How to get HTML from page in WebView?

看到上面的线程后,我写了下面的代码.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆