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开发者_Go百科 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.
精彩评论