I'm trying to parse a html into my swift project using Kanna, I used this What is the best practice to parse html in swift?, as a guide.
This is the code I'm using to parse the html:
if let doc = Kanna.HTML(html: myHTMLString, encoding: String.Encoding.utf8) {
var bodyNode = doc.body
if let inputNodes = bodyNode?.xpath("//a/@href[ends-with(.,'.txt')]") {
for node in inputNodes {
print(node.content)
}
}
}
Now I dont have any experince with this, but I believe that I have to change the .xpath("//a/@href[ends-with(.,'.txt')]")
to get the specific information I need.
This is the html im trying to parse:
view-source:https://en.wikipedia.org/wiki/List_of_inorganic_compounds
What I want from this line is the title: "Aluminium antimonide" and the chemical formular: "AlSb".
Can anybody tell me what to write in the .xpath(...)
, or maybe explain to me how it works?