23

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.

dejavu
  • 3,236
  • 7
  • 35
  • 60
  • 1
    Ok 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 Answers4

17

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:

  1. Right Click on project
  2. BuildPath
  3. Add External Archives
  4. select the .jar file

You can parse according to tag/parent/child very comfortably

Rasel
  • 15,499
  • 6
  • 40
  • 50
5

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

Community
  • 1
  • 1
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
2

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.

sunriser
  • 770
  • 3
  • 12
  • 1
    I 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
0

Use the WebView. Simple!!

http://developer.android.com/reference/android/webkit/WebView.html

Kumar Bibek
  • 9,016
  • 2
  • 39
  • 68
  • 2
    Webview 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