android how get url in page loaded- loading

前端 未结 2 1232
终归单人心
终归单人心 2021-01-26 03:17

hello everyone i want to know if there is any way to find url in page loaded in webview for example

webview.loadurl(\"stackoverflow.com\") // this is url 
string         


        
2条回答
  •  日久生厌
    2021-01-26 03:45

    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());
    

    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;
                    }
                 }
    
        }
    

    This can help for grabbing

提交回复
热议问题