views:

204

answers:

2

I'm working on an application that needs to get the source of a web page from a link, and then parse the html from that page.

Could you give me some examples, or starting points where to look to start writing such an app?

A: 

If you have a look here or here, you will see that you can't do that directly with android API, you need an external librairy...

You can choose between the 2 here's hereabove if you need an external librairy.

Sephy
that depends on the kind of webpage you have and want to parse. If you are only looking for some specific values you totally can grab this values with some regular expression :) I would only use a new external lib if the use case for that library is complicated enough
Janusz
fair enough. Regex are quite easy to go with.but then you need to load the whole page and grab each tag you're interested with a custom regex in aren't you?
Sephy
before using regex we need to get the html source as a string. how to do that?
Praveen Chandrasekaran
+1  A: 

You can use HttpClient to perform an HTTP GET and retrieve the HTML response, something like this:

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);

String html = "";
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null)
{
    str.append(line);
}
in.close();
html = str.toString();
mbaird