PDA

View Full Version : Can anyone give me a hint on how I might parse this HTML?




chrono1081
Feb 12, 2012, 12:54 PM
Hi guys,

I'm working on an app for practice that grabs data from a webpage and uses it to highlight sections on a map.

The first part in solving this problem is to parse HTML data from a webpage. I have code that grabs the webpage but I'm having trouble figuring out how I may grab the information I need.

Here is a snippet of the HTML I need to grab:


<tr bgcolor="#95BCE3">
<td>Snow Drop - Beginner's Area</td>
<td align="center">Yes</td>
<td align="center">Yes</td>
</tr>
<tr bgcolor="#CCCCCC">
<td>Fox Trot</td>
<td align="center">Yes</td>
<td align="center">No</td>
</tr>
<tr bgcolor="#95BCE3">
<td>Run Out</td>
<td align="center">Yes</td>
<td align="center">Yes</td>
</tr>

I haven't found anything in Apples documentation that seems to be able to help me with this (everything is XML or JSON) but obviously I could be looking in the wrong spot.

Basically what I'm trying to do is grab the information in bold "Snow Drop - Beginner's Area" and the two parts underneath (the yes and no sections). Once everything is grabbed it would look like this:

Snow Drop - Beginners Area
Yes
Yes

Fox Trot
Yes
No

..etc

I understand there are third party libraries for this but I was trying to use all iOS/Objective-C if possible and minimize my reliance on anything third party.

Can anyone give me some suggestions on how I may go about this?

EDIT: I should add that the names are unchanging, so I could search the file (currently stored in an NSData object) for "Snow Drop - Beginners Area" then use some type of search function to grab the next two instances of either yes or no, then move on to search for "Fox Trot" and do the same thing.

I'm assuming there is a more elegant solution to this so I was wondering if anyone had any ideas.

EDIT2: I discovered the NSScanner class. I'm going to try and get it working with this.