html - parsing/escape in Swift -


currently have html string (here part of it) in swift want escape special part

<tr style="color:white;background-color:#32b4fa;border-width:1px;border-style:solid;font-weight:normal;">     <th scope="col" style="border-color:black;font-family:verdana,geneva,arial,helvetica,sans-serif;font-size:x-small;width:25px;">&nbsp;</th><th scope="col" style="border-color:black;font-family:verdana,geneva,arial,helvetica,sans-serif;font-size:x-small;width:20px;">park-<br>stätte</th><th scope="col" style="border-color:black;font-family:verdana,geneva,arial,helvetica,sans-serif;font-size:x-small;width:25px;">parkmöglichkeit</th><th scope="col" style="border-color:black;font-family:verdana,geneva,arial,helvetica,sans-serif;font-size:x-small;width:25px;">anzahl stellplätze</th><th scope="col" style="border-color:black;font-family:verdana,geneva,arial,helvetica,sans-serif;font-size:x-small;width:25px;">freie stellplätze</th> </tr> <tr style="color:#000066;">     <td align="center" style="border-width:1px;border-style:solid;font-size:x-small;width:25px;">         <span id="gridview1__id_0" title="kennzeichen" readonly="true" style="display:inline-block;border-width:0px;font-family:verdana,geneva,arial,helvetica,sans-serif;font-size:x-small;width:25px;">p1</span>      </td>     <td align="center" style="border-width:1px;border-style:solid;font-size:x-small;">         <img src="images/symbol_tiefgarage.jpg" style="width:20px;" />     </td>     <td align="left" style="border-width:1px;border-style:solid;font-size:small;">         <a id="gridview1_hyperlink1_0" href="http://www.paderborn.de/microsite/asp/parken_in_der_city/tg_koenigsplatz.php" target="_top" style="display:inline-block;font-family:verdana,geneva,arial,helvetica,sans-serif;font-size:x-small;width:150px;">königsplatz</a>     </td>     <td align="center" style="border-width:1px;border-style:solid;font-size:x-small;width:40px;">                            <span id="gridview1__anzahlplaetze_0" title="anzahl plätze" readonly="true" style="display:inline-block;border-width:0px;font-family:verdana,geneva,arial,helvetica,sans-serif;font-size:x-small;">810</span>      </td>     <td align="center" style="border-width:1px;border-style:solid;font-size:smaller;width:40px;">         <span id="gridview1__anzahlfreieplaetze_0" title="freie plätze" readonly="true" style="display:inline-block;border-width:0px;font-family:verdana,geneva,arial,helvetica,sans-serif;font-size:x-small;">0</span>      </td> </tr> 

the part me interesting "810"( 0-1000 or text string) from

 <td align="center" style="border-width:1px;border-style:solid;font-size:x-small;width:40px;">                            <span id="gridview1__anzahlplaetze_0" title="anzahl plätze" readonly="true" style="display:inline-block;border-width:0px;font-family:verdana,geneva,arial,helvetica,sans-serif;font-size:x-small;">810</span>      </td> 

i did try use regex did not work out me.

i suggest use xml/html parser supports css selectors retrieve string, since span contains string has id = "gridview1__anzahlplaetze_0", , can use query "#gridview1__anzahlplaetze_0" retrieve it.

for example, swift library called fuzi wraps libxml2

import fuzi let doc = try? htmldocument(string: htmlstring) if let result = doc?.firstchild(css: "#gridview1__anzahlplaetze_0") {     print(result.stringvalue) } 

the above code tested.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -