document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package com.example.jsoupexample;
  2. import java.io.IOException;
  3. import org.jsoup.Jsoup;
  4. import org.jsoup.nodes.Document;
  5. import org.jsoup.nodes.Element;
  6. import org.jsoup.select.Elements;
  7. import android.app.Activity;
  8. import android.app.ProgressDialog;
  9. import android.os.AsyncTask;
  10. import android.os.Bundle;
  11. import android.util.Log;
  12. import android.view.View;
  13. import android.widget.Button;
  14. import android.widget.TextView;
  15.  
  16.  
  17. public class MainActivity extends Activity {
  18.  
  19.     private static final String URL = "http://howto.unixdev.net";
  20.  
  21.     ProgressDialog mProgressDialog;
  22.  
  23.     @Override
  24.     public void onCreate(Bundle savedInstanceState) {
  25.         super.onCreate(savedInstanceState);
  26.         setContentView(R.layout.activity_main);
  27.  
  28.         Button btnFetchData = (Button) findViewById(R.id.btnData);
  29.         btnFetchData.setOnClickListener(new View.OnClickListener() {
  30.  
  31.             public void onClick(View v) {
  32.                 // TODO Auto-generated method stub
  33.                 new FetchWebsiteData().execute();
  34.             }
  35.         });
  36.     }
  37.  
  38.     private class FetchWebsiteData extends AsyncTask<Void, Void, Void> {
  39.         String websiteTitle, websiteDescription;
  40.  
  41.         @Override
  42.         protected void onPreExecute() {
  43.             super.onPreExecute();
  44.             mProgressDialog = new ProgressDialog(MainActivity.this);
  45.             mProgressDialog.setMessage("Loading...");
  46.             mProgressDialog.setIndeterminate(false);
  47.             mProgressDialog.show();
  48.         }
  49.  
  50.         @Override
  51.         protected Void doInBackground(Void... params) {
  52.             try {
  53.                 // Connect to website
  54.                 Document document = Jsoup.connect(URL).get();
  55.                 // Get the html document title
  56.                 websiteTitle = document.title();
  57.                
  58.                 Elements description = document.select("td.right td a");
  59.                 // Locate the content attribute
  60.                 websiteDescription = description.attr("href");
  61.                
  62.                 //print each row
  63.                 int i=0;
  64.                 for (Element file : document.select("td.right td a")) {
  65. //                    System.out.println(file.attr("href"));
  66.                     i++;
  67.                     Log.e("row"+i,file.attr("href"));
  68.                 }
  69.             } catch (IOException e) {
  70.                 e.printStackTrace();
  71.             }
  72.             return null;
  73.         }
  74.  
  75.         @Override
  76.         protected void onPostExecute(Void result) {
  77.             // Set title into TextView
  78.             TextView txttitle = (TextView) findViewById(R.id.txtData);
  79.             txttitle.setText(websiteTitle + "\\n" + websiteDescription);
  80.             mProgressDialog.dismiss();
  81.         }
  82.     }
  83. }
');