Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在WebView UWP中按ID获取dom元素_Javascript_C#_Xaml_Webview_Uwp - Fatal编程技术网

Javascript 在WebView UWP中按ID获取dom元素

Javascript 在WebView UWP中按ID获取dom元素,javascript,c#,xaml,webview,uwp,Javascript,C#,Xaml,Webview,Uwp,我打算从网站上获取dom元素的内容,我无法使用 var html = await client.GetAsync("http://example.com/test.html"); 因为特定的dom元素是在执行JS之后填充的 我可以使用webview来托管内容,但这并不能解决问题 我不能使用这两个名称空间,因为它位于System.Windows.Forms命名空间下,这在通用Windows平台中不受支持! 另一个选项是InvokeAsync await webView5.InvokeScript

我打算从网站上获取dom元素的内容,我无法使用

var html = await client.GetAsync("http://example.com/test.html");
因为特定的dom元素是在执行JS之后填充的 我可以使用webview来托管内容,但这并不能解决问题 我不能使用这两个名称空间,因为它位于System.Windows.Forms命名空间下,这在通用Windows平台中不受支持! 另一个选项是InvokeAsync

await webView5.InvokeScriptAsync("doSomething", null);  
如图3的场景5所示 但这只是触发事件,无助于获取dom元素(甚至在JS执行完成后获取源代码)。 //该应用程序是C#UWP,而不是Winjs。您可以使用库查询下载的DOM。看到或寻找更多,有很多

或者,您可以运行javascript来完成您需要的操作,并返回一个包含您的ID的字符串。如您所见,
InvokeScriptAsync
返回
string
,该字符串可以包含您的javascript返回的任何内容。例如,要使用javascript获取DOM:

var result = await this.webView.InvokeScriptAsync("eval", new[] { "document.documentElement.outerHTML;" });