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:
- september 2011 09:47 Ankommet til DANMARK
- september 2011 07:17 Ankommet til omdeling 6710 Esbjerg V Posthus
- 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 r开发者_如何学编程esEntityGet = 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? :-/
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
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
精彩评论