简体   繁体   中英

In Android is it possible to only show a specific ID of an html element using WebView

I am wokring on an Android app that needs to be able to access a specific html ID and only display that information. I am trying to get some like this for example www.example.com/test.php#FeatureGroup I tried to put that in with a WebView but it only loads it to that item which is what I was expecting I would like to remove the rest of the stuff from the site is that possible and do I need to use something other than a WebView.

As I suppose you do not have access to the page you are trying to modify, so as @Mak says you need to inject javascript when the page has been loaded. See example:

   final WebView webview = (WebView) this.findViewById(R.id.webview);
   WebSettings webSettings = webview.getSettings();

   // Enable Javascript for interaction
   webSettings.setJavaScriptEnabled(true);
   webview.setWebViewClient(new WebViewClient() {  
       @Override  
       public void onPageFinished(WebView view, String url)  
       {  
           webview.loadUrl(
                           "javascript:(function() { " +  <js to alter dom>  + "})()");
       }  
   });

   webview.loadUrl("www.example.com");

Other option is to make the HTTP query yourself retrieving the HTML and web-scraping it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM