Simple web crawler on android?

admin

Administrator
Staff member
Configuration : Eclipse for Android Developper - jre1.7 - Windows 8 :)s) -

I am developing a small application on Android. In the moment, I would like just print my website on the MainActivity. I've really tried to realize it with stackoverflow and my patience and I'm falling on the following source code :

Code:
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.io.Reader; 
import java.util.HashSet; 
import java.util.Set; 
import org.apache.http.HttpResponse; 
import org.apache.http.client.ClientProtocolException; 
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient; 

public class Crawler {



            public static void main(String[] args) throws ClientProtocolException, IOException {
            crawlPage("http://www.google.com/");
        }       

                       private static void crawlPage(String string) {
                // TODO Auto-generated method stub
                        }

        static Set<String checked = new HashSet<String();

        @SuppressWarnings("unused")         private static void main(String url) throws ClientProtocolException, IOException {

            if (checked.contains(url))
                return;

            checked.add(url);

            System.out.println("Crawling: " + url);

            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet("http://www.bratiska.wordpress.com");
            HttpResponse response = client.execute(request);

            Reader reader = null;
            try {
                reader = new InputStreamReader(response.getEntity().getContent());


                String link="";
                new ParserDelegator().parse(reader, link, true);

                if (link.startsWith("http://www.libnum.fr"))
                        crawlPage(link);

            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
      } 
}

Need help for the
Code:
private static void crawlPage()
method !