Android : How to get the table values from the html page in android by jsoup

on Thursday, April 2, 2015


I want to extract values from table from this site from the below table as shownenter image description here


i want all the content from the table to extracted.


Below is my android code.



public class MainActivity extends Activity {

// URL Address

String url = "http://results.vtu.ac.in/vitavi.php";
ProgressDialog mProgressDialog;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Locate the Buttons in activity_main.xml

Button descbutton = (Button) findViewById(R.id.descbutton);

// Capture button click
descbutton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// Execute Description AsyncTask
new Description().execute();
}
});


}

// Description AsyncTask
private class Description extends AsyncTask<Void, Void, Void> {
String desc;

@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setTitle("Android Basic JSoup Tutorial");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}

@Override
protected Void doInBackground(Void... params) {
try {
// Connect to the web site
Document document = Jsoup.connect(url).data("rid", "1rn12ec080")
.data("submit", "SUBMIT")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36")
.post();



Elements description = document
.select("meta[name=description]");

// Locate the content attribute
desc = description.attr("content");
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

@Override
protected void onPostExecute(Void result) {
// Set description into TextView
TextView txtdesc = (TextView) findViewById(R.id.desctxt);
txtdesc.setText(desc);
mProgressDialog.dismiss();
}
}


However if i try to execute the code, it get a blank screen when i click on the descbutton.


Here is the network tab, it shows the vitavi.php where the rid(input) to be given.


enter image description here


0 comments:

Post a Comment