开发者

html parsing in objective-c [duplicate]

开发者 https://www.devze.com 2023-02-12 15:51 出处:网络
This question already has answers here: parsing HTML on the iPhone [closed] 开发者_运维百科(9 answers)
This question already has answers here: parsing HTML on the iPhone [closed] 开发者_运维百科 (9 answers) Closed 3 years ago.

I need to parse an html so any one tell me how to do this in objective-c?


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.

Here are some examples in 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")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号