I'm developing an iOS app in which I need to parse HTML from a link with the swiftsoup library. I have done it. But it shows all the table data as a string. I need to get separate data which should be stored in separate arrays.
Here is the table:
<table width="880" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="81"><strong>Trip Name </strong></td>
<td width="159"><div align="center"><strong>Starting Time from Campus </strong></div></td>
<td width="186"><div align="center"><strong>Starting Spot & Time </strong></div></td>
<td width="444"><strong>Remarks</strong></td>
</tr>
<tr>
<td><div align="center">Normal-1</div></td>
<td><div align="center">6:30 AM </div></td>
<td>Rupsha, 7:20 AM </td>
<td>Will back via Royalmore & Ferighat </td>
</tr>
<tr>
<td><div align="center">Normal-1</div></td>
<td><div align="center">6:45 AM </div></td>
<td>Moylapota, 7:25 AM </td>
<td>Will back via Shibbari - Sonadangha </td>
</tr>
</table>
And I have done to parse a string like Trip Name Starting Time from Campus Starting Spot & Time Remarks Normal-1
The code I've used :
let doc: Document = try! SwiftSoup.parse(html)
for element: Element in try! doc.select("table[width=880]")
{
let linkText : String = try! element.text();
print(linkText)
}
The Normal-1, 6:30AM, 7:20AM , Will back via Royalmore & Ferighat will be stored 4 separate array.