Reputation: 3254
How can we retrieve data from a website and parse it into a readable format in the Android application? This means I want to extract data from website and use it in my android application, formatted in my way. It could be any website.
Upvotes: 23
Views: 112914
Reputation: 34360
Use this
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://www.someplace.com");
ResponseHandler<String> resHandler = new BasicResponseHandler();
String page = httpClient.execute(httpGet, resHandler);
This can be used to grab the whole webpage as a string of html, i.e., "<html>...</html>"
Note
You need to declare the following 'uses-permission' in the android manifest xml file
... answer by @Squonk here
And also check this answer
Upvotes: 5
Reputation: 780
You can do the HTML parsing but it is not at all recommended instead ask the website owners to provide web services then you can parse that information.
Upvotes: 2
Reputation: 9117
Use the WebView. Simple!!
http://developer.android.com/reference/android/webkit/WebView.html
Upvotes: 0
Reputation: 15477
You can use jsoup
to parse any kind of web page. Here you can find the jsoup library and full source code.
Here is an example: http://desicoding.blogspot.com/2011/03/how-to-parse-html-in-java-jsoup.html
To install in Eclipse:
You can parse according to tag/parent/child very comfortably
Upvotes: 17