is there any Objective C library for parsing HTML, like python's BeautifulSoup? Thanks
Asked
Active
Viewed 6,346 times
8
-
See [How to Parse HTML on iOS](http://www.raywenderlich.com/14172/how-to-parse-html-on-ios). – Rob Jul 20 '14 at 19:11
2 Answers
8
From Apple's part there is NSXMLDocument and NSXMLParser, which support tidied HTML input. (Tree-Based XML Programming Guide)
On iOS (4.3) there's currently no NSXMLDocument available, so you'd have to use either NSXMLParser or libxml2.2.
Some more informations on potential problems with parsing malformed HTML:
What's the best approach for parsing XML/'screen scraping' in iOS? UIWebview or NSXMLParser?
The most reliable solution is to use an off-screen WebView, load the HTML source into it and then access its DOM tree.

Community
- 1
- 1

Regexident
- 29,441
- 10
- 93
- 100
-
Not to say you're wrong about any of the rest, but [NSXMLParser](http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html) _is_ available on iOS. – jscs May 03 '11 at 16:35
-
You're absoutely right. I had added NSXMLParser to my answer afterwards. Will rephrase it. Thanks. :) – Regexident May 03 '11 at 17:04
3
The best way I have found is NSXMLParser
+ libtidy
. However, there are many third party libraries are available now which makes parsing easier. (last answer was written in 2011).
- Google's Gumbo HTML5 parser is pretty good. It's written in pure C99 and you can use it with Objective C (use a wrapper like this one).
- If you want pure Objective C libraries then Ono or hpple are good. HTMLReader is also a good alternative.
- If Swift is your thing, you could use NDHpple which is a swift wrapper based on hpple. Or You could use Swift-HTML-Parser. (Bonus: Alamofire is as good as Python Requests and is a joy to use)

avi
- 9,292
- 11
- 47
- 84