jsoup fetching and displaying table contents in android

user4323984

I have a java program which fetches the table contents from This link. I want to do the same in android by displaying it in a textview.

Below is my java code

public class VtuFetch {
    public static void main(String[] args) throws Exception {

         Document doc = Jsoup.connect("http://www.fastvturesults.com/check_new_results/1rn11cs030").
                userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36").get();
        for (Element table : doc.select("table[id=scell]")) {
            for (Element row : table.select("tr:gt(0)")) {
               Elements tds = row.select("td:not([rowspan])");
               System.out.println("Semester"+" "+"Attempt"+" "+" "+"Total Marks"+" "+"     Result"+" "+"                          Percentage");
               System.out.println(tds.get(0).text() + "        " + tds.get(1).text()+"          "+ tds.get(2).text()+"            "+ tds.get(3).text()+"                              "+ tds.get(4).text());
            }
       }
    }
}

Below is my android code which fetches the same link.

private class GetMakrs extends AsyncTask<Void, Void, Void> {
        String desc;
        Elements tds;
        @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 doc = Jsoup.connect("http://www.fastvturesults.com/check_new_results/1rn11cs030").
                            userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36")
                            .get();

                                // Using Elements to get the Meta data
                Elements description = doc.select("meta[name=description]");
                for (Element table : doc.select("table[id=scell]")) {
                    for (Element row : table.select("tr:gt(0)")) {
                       Elements tds = row.select("td:not([rowspan])");
                       System.out.println("Semester"+" "+"Attempt"+" "+" "+"Total Marks"+" "+"     Result"+" "+"                          Percentage");

                       System.out.println(tds.get(0).text() + "        " + tds.get(1).text()+"          "+ tds.get(2).text()+"            "+ tds.get(3).text()+"                              "+ tds.get(4).text());


                    }
               }
                // 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.MarksShow);
            txtdesc.setText(desc);
            mProgressDialog.dismiss();
        }
    }

I am able to retrive the name of the person, but the table contents are not getting displayed.

P.S. The java Code works correct, i am having problem porting it to android

JonasCz

This should set the correct text instead of printing it:

private class GetMakrs extends AsyncTask<Void, Void, Void> {
        String desc = ""; //<-Important!
        Elements tds;

        ...

        @Override
        protected Void doInBackground(Void... params) {
            try {
                // Connect to the web site
                 ...

            Elements description = doc.select("meta[name=description]");
             for (Element table : doc.select("table[id=scell]")) {
                for (Element row : table.select("tr:gt(0)")) {
                 Elements tds = row.select("td:not([rowspan])");
                 desc = desc + "Semester"+" "+"Attempt"+" "+" "+"Total Marks"+" "+"     Result"+" "+"                          Percentage";

                 desc = desc + "\n" + tds.get(0).text() + "        " + tds.get(1).text()+"          "+ tds.get(2).text()+"       "+tds.get(3).text()+"      "+ tds.get(4).text();

                 desc = desc + "\n";


                    }
               }
                ...
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jsoup fetching and displaying table contents in android

From Dev

Using jsoup to get contents of a table

From Dev

Displaying XML Contents in a table + easy search with php

From Dev

Android app crashes when using AsyncTask for fetching an url with jsoup

From Dev

SWT : Fetching the contents of a dialog box and storing the data in a table viewer

From Dev

Fetching images from mysql database using php and displaying in gridview in android

From Dev

Displaying Data in a Table Android Development?

From Dev

Displaying Data in a Table Android Development?

From Dev

Adding delete button to php code displaying mysql table contents

From Dev

Error in the fetching contents of email

From Dev

fetching contents of a JSON Stream

From Dev

Java JSoup error fetching URL

From Dev

Jsoup select is not fetching all elements

From Dev

Jsoup get div contents

From Dev

Jsoup get div contents

From Dev

displaying retrived data from SQL as table in android

From Java

Displaying array contents in pairs

From Dev

Displaying contents on the same page

From Dev

Displaying contents of web scrape

From Dev

Displaying contents of a pdf in php

From Dev

Displaying contents of an associated model

From Dev

Displaying All Array Contents

From Java

Android Studio/Intellij Idea: "Table of Contents" for a class

From Dev

Email sqlite database table contents in android

From Dev

How to get the contents of a Table Layout in Android

From Dev

Include table of contents in table of contents

From Dev

Bootstrap Popover Displaying the Same Contents

From Dev

A customized Dialog is displaying misplaced contents

From Dev

Displaying contents of a knockout observable array

Related Related

HotTag

Archive