0

So i'm working on a track and trace app. And i need to pull information from this site: http://www.postdanmark.dk/tracktrace/TrackTrace.do?i_stregkode=RA076673982CN

My problem is that i dont know how to pick this part:

  1. september 2011 09:47 Ankommet til DANMARK
  2. september 2011 07:17 Ankommet til omdeling 6710 Esbjerg V Posthus
  3. september 2011 11:57 Udleveret til privat

and only that part.

Here's my code that downloads the whole html page:

try {
        HttpClient client = new DefaultHttpClient();  
        String getURL = "http://www.postdanmark.dk/tracktrace/TrackTrace.do?i_stregkode=RA076673982CN";
        HttpGet get = new HttpGet(getURL);
        HttpResponse responseGet = client.execute(get);  
        HttpEntity resEntityGet = responseGet.getEntity();  
        if (resEntityGet != null) {  
                    //do something with the response
                    Log.i("GET RESPONSE",EntityUtils.toString(resEntityGet));
                }
} catch (Exception e) {
    e.printStackTrace();
}

I have looked at several links and i cant seem to find anything that shows how to get a certain part of a html site like the:

<tbody>  

<tr> 
<td valign="top">19. september 2011</td>
<td valign="top">09:47</td>
<td valign="top">Ankommet til DANMARK</td>
</tr>

<tr> 
<td valign="top">20. september 2011</td>

<td valign="top">07:17</td>
<td valign="top">Ankommet til omdeling 6710 Esbjerg V Posthus</td>
</tr>

<tr> 
<td valign="top">20. september 2011</td>
<td valign="top">11:57</td>
<td valign="top">Udleveret til privat</td>

</tr>

</tbody>

I need my parser to get that part, but i haven't found or understood how :(

Can any of you show me an example on how to do it? :-/

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
BoinQ
  • 27
  • 5

2 Answers2

1

You need to parse the HTML and pull out the data you want using something like TagSoup/etc. (not sure if that works on Android). You could try to pull it out using regex, but...

RegEx match open tags except XHTML self-contained tags

Community
  • 1
  • 1
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • Well android is java, so there must be some way in java, i don't know if the tagsoup method works in java, i have never do it before – BoinQ Oct 02 '11 at 00:31
  • and as i can see it in the source code of the site, i need to restrict the httpget to and the content in between those 2 tags, and then get that parsed somehow to my layout. – BoinQ Oct 02 '11 at 01:49
  • The GET will get the page; you can't "restrict" the GET. – Dave Newton Oct 02 '11 at 01:50
  • how do i "restrict" it to only get the part of the site? – BoinQ Oct 02 '11 at 02:02
  • You don't; I thought I just said that. You get the entire page, then parse out the parts you want. – Dave Newton Oct 02 '11 at 02:08
  • how do i parse the part? – BoinQ Oct 02 '11 at 02:12
  • okay i have been looking at the code, trying to get it to read my track and trace site, but i cant get it to work, do you think you can help me out? – BoinQ Oct 02 '11 at 03:11
0

try using the sax parser

http://developer.android.com/reference/javax/xml/parsers/SAXParser.html

you just give it an input stream to the site page and then you can select which tags to keep

here is an example:

http://about-android.blogspot.com/2010/02/sample-saxparser-in-android.html

Ahmed Salem
  • 3,947
  • 1
  • 21
  • 40