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.
-
1Ok fine i will ask the website owners... but what actually want is that for example you have a website in which you publish many articles.. i just want to get the headlines of that article in the app.. you can take this as an example.. – dejavu Jul 20 '11 at 13:16
-
Got the xml file... now need to know how to parse the xml into my android app.. – dejavu Jul 20 '11 at 13:20
-
You can look on this one : http://stackoverflow.com/questions/2971155/what-is-the-fastest-way-to-scrape-html-webpage-in-android or you can look on this one: http://blog.andrewpearson.org/2010/07/android-html-parsing.html – Khafaga Feb 01 '13 at 02:16
4 Answers
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:
- Right Click on project
- BuildPath
- Add External Archives
- select the .jar file
You can parse according to tag/parent/child very comfortably

- 15,499
- 6
- 40
- 50
-
1
-
Will this jsoup work in android app?? i dunno how it works.. looks nice.. but will this work in my android app?? – dejavu Jul 20 '11 at 13:17
-
2The above answer along with this http://stackoverflow.com/a/4523525/568169 , works brilliantly! – Anirudh Feb 01 '12 at 03:55
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

- 1
- 1

- 33,936
- 20
- 234
- 300
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.

- 770
- 3
- 12
-
1I will be uploading the data on my own web server. How do I proceed to include that data in my Android app? – Si8 Jul 09 '14 at 19:01
Use the WebView. Simple!!
http://developer.android.com/reference/android/webkit/WebView.html

- 9,016
- 2
- 39
- 68
-
2Webview will load the website and he can get full source as string.But he needs the parsed data to use in his application – Rasel Jul 20 '11 at 11:27
-
Well, we need to know exactly what he wants to filter out and based on that, we could refine our answers. I like @riser 's answer. – Kumar Bibek Jul 20 '11 at 11:34
-
yes,some web site owners provide data as xml format.That is really great to have.But whatever you are getting in well known format or not you can parse – Rasel Jul 20 '11 at 11:36