iOS Hpple HTML parse -
so, need parse contents of website tableview in application. tried hpple , in testcases works. in specific case can't 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"> </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 2 main elements (<table></table>
) wich contents want populate uitableview.
my goal have 1 section per table, , inside each section contents of table. section-headers name should "date".
tfhpple *parser = [tfhpple hpplewithhtmldata:htmldata]; nsstring *xpathquerystring = @"/html/body/a"; nsarray *nodes = [parser searchwithxpathquery:xpathquerystring]; (tfhppleelement *element in nodes) { nsstring *temp = [[element firstchild] content]; if (temp.length == 10) { [day addobject:temp]; } }
in nsmutablearray *day
save dates , works fine. 2 sections right names. try receive tables contents cant work... want 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 can store newelement
(s) date 1 in 1 array , elements date 2 in element.
edit: e.g
newelement.day = @"07.07.2015";
of course needsnewelement.day = [[hppleparse firstchild] content];
this can achieved htmlkit.
here few examples of can using html provided:
htmldocument *document = [htmldocument documentwithstring:html]; nsmutablearray *days = [ nsmutablearray array]; nsarray *links = [document queryselectorall:@"a"]; (htmlelement *link in links) { if (link.textcontent.length == 10) { [days addobject:link.textcontent]; } } // example can: // <tr> elements children of table classname 'k' nsarray *tablekrows = [document queryselectorall:@"table.k > tr"]; // <td> elements descendants of table classname 'k' nsarray *tablekdata = [document queryselectorall:@"table.k td"]; // collect content of <td> elements in `array` nsmutablearray *array = [nsmutablearray array]; (htmlelement *td in tablekdata) { nsstring *content = [td.textcontent stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]]; [array addobject:content]; }
let me know if need further help.
htmlkit pure objective-c html parser css3 selectors support. not wrapper around libxml or other library, rather complete whatwg html specification-compliant implementation.
Comments
Post a Comment