UWP Webview get links from webpage into an array

旧街凉风 提交于 2019-12-05 21:31:47

The InvokeScriptAsync can only return the string result of the script invocation.

Return value

When this method returns, the string result of the script invocation.

So if you want get links form a web page, you need put all the links into a string to return. For a C# example:

string html = await webview.InvokeScriptAsync("eval", new string[] { "[].map.call(document.getElementsByTagName('a'), function(node){ return node.href; }).join('||');" });
System.Diagnostics.Debug.WriteLine(html);

Here I use

[].map.call(document.getElementsByTagName('a'), function(node){ return node.href; }).join('||');

to put all the links into a string. You may need to change this JavaScript code to implement your own.

After this you can split the string into a array like:

var links = html.Split(new[] { "||" }, StringSplitOptions.RemoveEmptyEntries);

Although I used C# for example, but the VB code should be similar.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!