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">                 ***&nbsp;&nbsp; version 1&nbsp;&nbsp; ***              </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">                 &nbsp;name              </th>              <th width="50">                 nr.              </th>              <th width="50">                 &nbsp;mate              </th>              <th width="50">                 spot              </th>              <th width="50">                 &nbsp;map              </th>              <th width="150"></th>           </tr>           <tr class="k">              <th rowspan="5" class="k">                              </th>              <td>                 &nbsp;first              </td>              <td>                 3              </td>              <td>                 &nbsp;              </td>              <td></td>              <td>                 &nbsp;              </td>              <td>                 &nbsp;test              </td>           </tr>           <tr>              <td>                 &nbsp;second              </td>              <td>                 4              </td>              <td>                 &nbsp;              </td>              <td></td>              <td>                 &nbsp;              </td>              <td>                 &nbsp;test              </td>           </tr>           <tr>              <td>                 &nbsp;sie              </td>              <td>                 8              </td>              <td>                 &nbsp;              </td>              <td></td>              <td>                 &nbsp;              </td>              <td>                 &nbsp;test              </td>           </tr>           <tr>              <td>                 &nbsp;sie              </td>              <td>                 9              </td>              <td>                 &nbsp;              </td>              <td></td>              <td>                 &nbsp;              </td>              <td>                 &nbsp;test              </td>           </tr>           <tr>              <td>                 &nbsp;es              </td>              <td>                 10              </td>              <td>                 &nbsp;              </td>              <td></td>              <td>                 &nbsp;              </td>              <td>                 &nbsp;test              </td>           </tr>           <tr class="k">              <th rowspan="1" class="k">                 b              </th>              <td>                 &nbsp;red              </td>              <td>                 11              </td>              <td>                 &nbsp;              </td>              <td></td>              <td>                 &nbsp;              </td>              <td>                 &nbsp;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">                 ***&nbsp;&nbsp; version 1&nbsp;&nbsp; ***              </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">                 &nbsp;name              </th>              <th width="50">                 nr.              </th>              <th width="50">                 &nbsp;mate              </th>              <th width="50">                 spot              </th>              <th width="50">                 &nbsp;map              </th>              <th width="150"></th>           </tr>           <tr class="k">              <th rowspan="5" class="k">                 c              </th>              <td>                 &nbsp;dnk              </td>              <td>                 1              </td>              <td>                 &nbsp;              </td>              <td></td>              <td>                 &nbsp;              </td>              <td>                 &nbsp;test              </td>           </tr>           <tr>              <td>                 &nbsp;es              </td>              <td>                 1              </td>              <td>                 &nbsp;              </td>              <td></td>              <td>                 &nbsp;              </td>              <td>                 &nbsp;test              </td>           </tr>           <tr>              <td>                 &nbsp;dnk              </td>              <td>                 2              </td>              <td>                 &nbsp;              </td>              <td></td>              <td>                 &nbsp;              </td>              <td>                 &nbsp;test              </td>           </tr>           <tr>              <td>                 &nbsp;esta              </td>              <td>                 2              </td>              <td>                 &nbsp;              </td>              <td></td>              <td>                 &nbsp;              </td>              <td>                 &nbsp;test              </td>           </tr>           <tr>              <td>                 &nbsp;swb              </td>              <td>                 6              </td>              <td>                 &nbsp;naau              </td>              <td>                 f              </td>              <td>                 &nbsp;test              </td>              <td>                 &nbsp;              </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 needs newelement.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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -