本文介绍了android怎么样在页面加载装载时获取网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想知道是否有办法找到
网址页面中的WebView加载
例如:

hello everyone i want to know if there is any way to findurl in page loaded in webviewfor example

webview.loadurl("stackoverflow.com") // this is url 
string aa = -webivew.geturl() //in this way in kno url in adress bar

但我想知道的帮助链接>> <一个href=\"http://stackoverflow.com/questions/ask?title=android%20how%20get%20url%20in%20page%20loaded-%20loading#\">http://stackoverflow.com/questions/ask?title=android%20how%20get%20url%20in%20page%20loaded-%20loading#

或别的东西不CLIK它是这可能吗?

or something else without clik on it is this possible ?

我觉得跟jsoup有这样或没有?
我很困惑。

i think with jsoup there is way or not ?i'm confused.

推荐答案

把你的WebView第一客户端:WebViewClient,其中你会打电​​话给HTML:

Put a first client in your WebView : WebViewClient, in which you'll call the html :

@Override
public void onPageFinished(WebView view, String url) {
   webview1.loadUrl("javascript:alert(document.getElementsByTagName('body')[0].innerHTML);");
   }

然后,把第二个客户端:

And then, put a second client :

webview1.setWebChromeClient(new MyWebChromeClient());

而在WebChromeClient,把这个后已宣布一个布尔navigationTolink为false:

And in the WebChromeClient, put this, after having declared a boolean navigationTolink to false:

   @Override
   public boolean onJsAlert(final WebView view, String url, final String transfert, JsResult result) {
             if (!navigationtoLink) {
                Document html = Jsoup.parse(transfert);
                Elements links = html.select("a[href]");
                for (Element link : links) {
                    if (link.attr("href").contains("youtube.com")) { 
                    view.loadUrl(link.attr("href"));
                    navigationtoLink=true;
                }
             }

    }

可以帮助抓取

这篇关于android怎么样在页面加载装载时获取网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 04:48