1

Please note that this question is not a duplicate of How to display some part of webpage in android webview? or Android WebView: display only some part of website as they exclude some element whereas i want to include only one.

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    boolean validate=checkIfNet();
    if(!validate){
        finish();
    }
    setContentView(R.layout.activity_main);
    WebView wb = (WebView) findViewById(R.id.webview);
    wb.getSettings().setJavaScriptEnabled(true);
    wb.getSettings().setLoadWithOverviewMode(true);
    wb.getSettings().setUseWideViewPort(true);
    wb.getSettings().setJavaScriptEnabled(true);
    wb.getSettings().setBuiltInZoomControls(false);
    wb.getSettings().setPluginState(WebSettings.PluginState.ON);
    //wb.getSettings().setPluginsEnabled(true);
    //wb.setWebViewClient(new HelloWebViewClient());
    wb.loadUrl("http://www.dota2.com/leaderboards#europe");
}

private boolean checkIfNet() {
    boolean connected = false;
    ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    if(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED ||
            connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
        //we are connected to a network
        connected = true;
    }
    else
        connected = false;
    return connected;
}

}

Now while getting http://www.dota2.com/leaderboards#europe it gets the full page. I only want the table in there. The one with tbody id="leaderboard_body". I am kind of new so pls chill on me. Thanks in advance.

Rishav
  • 3,818
  • 1
  • 31
  • 49
  • Use the https://jsoup.org/ to get the interesting contents of the page and build own UI for extracted content. – Kamil Jun 17 '17 at 19:26
  • 1
    I think i just told u I m noob. Anyways thanks ill go through the docs to figure out maybe how to get the damn table. – Rishav Jun 17 '17 at 19:30
  • 1
    This tutorial should help: http://www.androidbegin.com/tutorial/android-jsoup-listview-images-texts-html-tables-tutorial/ – Kamil Jun 17 '17 at 19:33
  • Thats exactly what i needed Thanks mate. :) – Rishav Jun 17 '17 at 19:34

1 Answers1

1

Actually what you want to achieve technically is to remove some parts of the html.

What happens is that your webview will get all of the content of the URL you provided to it, this is inherent on how http works. The webview class doesn't let you choose to show only a specific part of the html, so what you must do is to remove what you don't want before rendering using javascript.

If you want to show it using a webview then the solutions in your post are what you want, if you want to parse the html and render it using Android UI classes then the jsoup solutions are what you want(however this is a bit overkill).

If you're really new to this my tip is: use an API. Probably something like https://docs.opendota.com/. The way virtually all apps(and websites) that are not static works is by using APIs. Here is an introduction on why you would want to do so instead of parsing with jsoup.

Thiago Valle
  • 449
  • 1
  • 6
  • 20