I need to parse the contents of a website into a tableview in my application. I tried hpple and in some testcases it works. But in my specific case I can't get it to work... HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="willi.css">
</link><script src="style.js" type="text/javascript"></script>
<title>Homepage</title>
</head>
<body>
<a name="oben"/>
<h1>Date</h1>
<br />
<a href="#07.07.2015">07.07.2015</a><br />
<a href="#07.08.2015">07.08.2015</a><br />
<a name="07.07.2015">
<hr />
</a>
<p class="page" style="text-align:left">
<h2>Date Tue, 7.7.2015</h2>
created: 7.7. 16:35 </p>
<p class="page" style="text-align:left">
<table class="F" border-width="3">
<colgroup>
<col width="899"/>
</colgroup>
<tr class="F">
<th rowspan="1" class="F">
*** Version 1 ***
</th>
</tr>
<tr class="F">
<th rowspan="1" class="F"></th>
</tr>
<tr class="F">
<th rowspan="1" class="F">
Testmessage 1
</th>
</tr>
<tr class="F">
<th rowspan="1" class="F">
Testmessage 2
</th>
</tr>
<tr class="F">
<th rowspan="1" class="F">
Testmessage 3
</th>
</tr>
<tr class="F">
<th rowspan="1" class="F"></th>
</tr>
<tr class="F">
<th rowspan="1" class="F">
Testmessage 4
</th>
</tr>
</table>
</p>
<p class="seite" style="text-align:left">
<h4>List:</h4>
<table class="k" border-width="3">
<tr>
<th width="50">
Team
</th>
<th width="50">
Name
</th>
<th width="50">
Nr.
</th>
<th width="50">
Mate
</th>
<th width="50">
Spot
</th>
<th width="50">
Map
</th>
<th width="150"></th>
</tr>
<tr class="k">
<th rowspan="5" class="k">
A
</th>
<td>
First
</td>
<td>
3
</td>
<td>
</td>
<td></td>
<td>
</td>
<td>
Test
</td>
</tr>
<tr>
<td>
Second
</td>
<td>
4
</td>
<td>
</td>
<td></td>
<td>
</td>
<td>
Test
</td>
</tr>
<tr>
<td>
Sie
</td>
<td>
8
</td>
<td>
</td>
<td></td>
<td>
</td>
<td>
Test
</td>
</tr>
<tr>
<td>
Sie
</td>
<td>
9
</td>
<td>
</td>
<td></td>
<td>
</td>
<td>
Test
</td>
</tr>
<tr>
<td>
Es
</td>
<td>
10
</td>
<td>
</td>
<td></td>
<td>
</td>
<td>
Test
</td>
</tr>
<tr class="k">
<th rowspan="1" class="k">
B
</th>
<td>
Red
</td>
<td>
11
</td>
<td>
</td>
<td></td>
<td>
</td>
<td>
Test
</td>
</tr>
</table>
</p>
<hr />
<a name="07.08.2015">
<hr />
</a>
<p class="page" style="text-align:left">
<h2>Date Thu, 8.7.2015</h2>
created: 7.7. 16:35 </p>
<p class="page" style="text-align:left">
<table class="F" border-width="3">
<colgroup>
<col width="899"/>
</colgroup>
<tr class="F">
<th rowspan="1" class="F">
*** Version 1 ***
</th>
</tr>
</table>
</p>
<p class="page" style="text-align:left">
<h4>List:</h4>
<table class="k" border-width="3">
<tr>
<th width="50">
Team
</th>
<th width="50">
Name
</th>
<th width="50">
Nr.
</th>
<th width="50">
Mate
</th>
<th width="50">
Spot
</th>
<th width="50">
Map
</th>
<th width="150"></th>
</tr>
<tr class="k">
<th rowspan="5" class="k">
C
</th>
<td>
Dnk
</td>
<td>
1
</td>
<td>
</td>
<td></td>
<td>
</td>
<td>
Test
</td>
</tr>
<tr>
<td>
Es
</td>
<td>
1
</td>
<td>
</td>
<td></td>
<td>
</td>
<td>
Test
</td>
</tr>
<tr>
<td>
Dnk
</td>
<td>
2
</td>
<td>
</td>
<td></td>
<td>
</td>
<td>
Test
</td>
</tr>
<tr>
<td>
Esta
</td>
<td>
2
</td>
<td>
</td>
<td></td>
<td>
</td>
<td>
Test
</td>
</tr>
<tr>
<td>
SWB
</td>
<td>
6
</td>
<td>
Naau
</td>
<td>
F
</td>
<td>
Test
</td>
<td>
</td>
</tr>
</table>
</p>
<hr />
</body>
</html>
The page contains two main elements (<table></table>
) with which contents I want to populate my UITableView.
My goal is to have one section per table, and inside each section all contents of the table. The section-headers name should be the "date".
TFHpple *Parser = [TFHpple hppleWithHTMLData:HtmlData];
NSString *XpathQueryString = @"/html/body/a";
NSArray *Nodes = [Parser searchWithXPathQuery:XpathQueryString];
for (TFHppleElement *element in Nodes) {
NSString *temp = [[element firstChild] content];
if (temp.length == 10) {
[Day addObject:temp];
}
}
In my NSMutableArray *Day
I save the dates and this works fine. I get 2 sections with the right names.
But as I try to receive the tables contents I can't get it to work...
I want something like
tableElement* newElement = [[tableElement alloc] init];
newElement.day = @"07.07.2015";
newElement.team = @"A";
newElement.name = @"First";
newElement.nr = @"3";
newElement.mate = @"";
newElement.spot = @"";
newElement.map = @"";
newElement.status = @"Test";
and then I can store all newElement
(s) for date one in one array and all elements for date two in another element.
edit: e.g
newElement.day = @"07.07.2015";
of course needs to be something likenewElement.day = [[hppleparse firstChild] content];