How can I get web content with HtmlAgilityPack after login?

c# html-agility-pack uwp webview

Question

I'm try to develop a UWP app that get data from my University website

I'm able to login with WebView and now I'm try to extract any text that show up after login

But I try to extract web content with HtmlAgilityPack but it got redirect to login page instead.

Here is what I did

private async void GetInfo(WebView sender, WebViewDOMContentLoadedEventArgs args)
{
     HtmlDocument doc = new HtmlDocument();
     HtmlWeb web = new HtmlWeb();
     doc = await web.LoadFromWebAsync(sender.Source.AbsoluteUri);
     var chunks = new List<string>();
     foreach (var item in doc.DocumentNode.DescendantsAndSelf())
     {
         if (item.NodeType == HtmlNodeType.Text)
         {
             if (item.InnerText.Trim() != "")
             {
                 chunks.Add(item.InnerText.Trim());
             }
         }
     }
}

As I check with Visual studio, all texts in chunks list is from login page not after login page

Accepted Answer

You can use InvokeScriptAsync in WebView to get Html. Call the below code after login using WebView

await webView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });

For more info:
Check out this answer
Sample app for LogIn to StackOverflow



Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow