1

I intend to get the content of a dom element from a website, I cant use

var html = await client.GetAsync("http://example.com/test.html");

as the specific dom element is populated after the JS is executed I can use a webview to host the content but that won't solve the problem I can't use HtmlDocument.GetElementById Method (String) either as it is under System.Windows.Forms namespace which isn't supported in Universal Windows Platform! Another option would be InvokeAsync

await webView5.InvokeScriptAsync("doSomething", null);  

as seen in scenario 5 of XAML WebView control sample but that just fires events and won't help in getting the dom element (or even the source code once the JS execution done). //The app is a C# UWP, not Winjs

divay pandey
  • 152
  • 4
  • 8

1 Answers1

2

You can use HtmlAgilityPack library to query DOM you downloaded. See example here or search for more, there are plenty.

Alternatively, you can run javascript which does what you need and returns a string containing your ID. As you see, InvokeScriptAsync returns String which can contain anything your javascript returned. F.e., this is how to get DOM with javascript:

var result = await this.webView.InvokeScriptAsync("eval", new[] { "document.documentElement.outerHTML;" });
Andrei Ashikhmin
  • 2,401
  • 2
  • 20
  • 34