Answer the question
In order to leave comments, you need to log in
How does HTML parsing work in Swift?
I started learning Swift using the example of a simple application in which I want to write data from a specific site without an API to a TableView. Googling led me to the Kanna library for parsing HTML content.
Work example:
import Kanna
let html = "<html>...</html>"
if let doc = Kanna.HTML(html: html, encoding: NSUTF8StringEncoding) {
print(doc.title)
// Search for nodes by CSS
for link in doc.css("a, link") {
print(link.text)
print(link["href"])
}
// Search for nodes by XPath
for link in doc.xpath("//a | //link") {
print(link.text)
print(link["href"])
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question