Can anyone give me a hint on how I might parse this HTML?

Discussion in 'iOS Programming' started by chrono1081, Feb 12, 2012.

  1. chrono1081, Feb 12, 2012
    Last edited: Feb 12, 2012

    chrono1081 macrumors 604


    Jan 26, 2008
    Isla Nublar
    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>[B]Snow Drop - Beginner's Area[/B]</td>
        <td align="center">[B]Yes[/B]</td>
        <td align="center">[B]Yes[/B]</td>
      <tr bgcolor="#CCCCCC">
        <td>[B]Fox Trot[/B]</td>
        <td align="center">[B]Yes[/B]</td>
        <td align="center">[B]No[/B]</td>
      <tr bgcolor="#95BCE3">
       <td>[B]Run Out[/B]</td>
        <td align="center">[B]Yes[/B]</td>
        <td align="center">[B]Yes[/B]</td>
    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

    Fox Trot


    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.

Share This Page