How to get inner html source from WebView in Xamarin Form - C#

后端 未结 2 846
孤独总比滥情好
孤独总比滥情好 2020-12-21 12:39

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 s

相关标签:
2条回答
  • 2020-12-21 12:52

    Here is my code:

     private async Task<string> GetHtml()
            {
                return await LoginWebViewItem.EvaluateJavaScriptAsync("document.body.innerHTML");
            }
    

    Then I call this from my method:

    string AllHtml = await GetHtml();
    
    0 讨论(0)
  • 2020-12-21 12:55

    You will need to use HybridWebView from Xamarin-Forms-Labs and register a callback. Documentation is here.

    In your C# code register a callback:

    this.hybridWebView.RegisterCallback("dataCallback", t => System.Diagnostics.Debug.WriteLine(t));
    

    Then evaluate some JS code calling the callback

    this.hybridWebView.Eval("Native(\"dataCallback\", document.body.innerHTML);");
    
    0 讨论(0)
提交回复
热议问题