xcode 在objective-c中解析html
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5089090/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
html parsing in objective-c
提问by SRI
I need to parse an html so any one tell me how to do this in objective-c?
我需要解析一个html,所以有人告诉我如何在objective-c中做到这一点?
回答by iska
Try HTMLKit. It is a pure Objective-C HTML parser with CSS3 Selectors support. It is not a wrapper around libxml or any other library, but rather a complete WHATWG HTML specification-compliant implementation.
试试HTMLKit。它是一个纯 Objective-C HTML 解析器,支持 CSS3 选择器。它不是 libxml 或任何其他库的包装器,而是一个完整的符合 WHATWG HTML 规范的实现。
Here are some examples in Swift:
以下是 Swift 中的一些示例:
let htmlString = "<div><h1>HTMLKit</h1><p>Hello there!</p></div>"
let document = HTMLDocument(string: htmlString)
let stuff = HTMLElement(tagName:"ul", attributes: ["class": "list"])
stuff.innerHTML = "<li>item 1<li>item 2"
let body = document.body!
body.appendNode(stuff)
let items = document.querySelectorAll(".list li")