I am trying to parse the following website so I display the data like this on iOS:
Saturday 6th September
Causeway
Bond's Glen Raceway
11:00am
RO
Two Day Meeting
Two Separate Days
An example of the website:
<div id="main-column">
<h1>September</h1>
<table align="center"><col width="200"><col width="150"><col width="100"><col width="120"><col width="330"><col width="300">
<h2>Saturday 06 September</h2>
<tr id="table1">
<td><b>Club</b></td>
<td><b>Venue</b></td>
<td><b>Start Time</b></td>
<td><b>Meeting Type</b></td>
<td><b>Number of Days for Meeting</b></td>
<td><b>Notes</b></td>
</tr>
<tr id="table2">
<td>Causeway</td>
<td>Bond's Glen Raceway</td>
<td>11:00am</td>
<td>RO</td>
<td>Two Day Meeting,<br> Two Separate Days</td>
<td></td>
</tr>
<tr id="table3">
<td>West Waterford</td>
<td>Ballysaggart</td>
<td>11:00am</td>
<td>RO</td>
<td>Two Day Meeting,<br> One Meeting Over Two Days</td>
<td></td>
</tr>
So far I have managed to get all of the dates with the following code:
-(void)loadData {
NSURL *url = [NSURL URLWithString:@"http://www.national-autograss.co.uk/september.htm"];
NSData *htmlData = [NSData dataWithContentsOfURL:url];
TFHpple *htmlParser = [TFHpple hppleWithHTMLData:htmlData];
NSString *xpathQueryString = @"//h2";
NSArray *eventNodes = [htmlParser searchWithXPathQuery:xpathQueryString];
NSMutableArray *eventDates = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in eventNodes) {
NSString *date = [[element firstChild] content];
[eventDates addObject:date];
}
_objects = eventDates;
[self.tableView reloadData];
}
Is the Xpath query I need for the data in the table something like //table/tr/td? I tried this and I got an immediate error of adding a nil object to an array.
Or am I better to get all of the tables as separate elements and then parse individually for the data inside?
Any help, guides or ideas would be very much appreciated.