【发布时间】:2016-11-22 18:07:15
【问题描述】:
我正在尝试使用 Kanna 将 html 解析到我的 swift 项目中,我使用此 What is the best practice to parse html in swift? 作为指南。
这是我用来解析 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)
}
}
}
现在我对此没有任何经验,但我相信我必须更改.xpath("//a/@href[ends-with(.,'.txt')]")才能获得我需要的具体信息。
这是我试图解析的 html:
查看源代码:https://en.wikipedia.org/wiki/List_of_inorganic_compounds
我想从这行得到标题:“锑化铝”和化学式:“AlSb”。
谁能告诉我在.xpath(...) 中写什么,或者向我解释它是如何工作的?
【问题讨论】: