I am creating an iOS app that needs to get some data from a web page. My first though was to use NSXMLParser initWithContentsOfURL:
and parse the HTML with the NSXMLParser
delegate. However this approach seems like it could quickly become painful (if, for example, the HTML changed I would have to rewrite the parsing code which could be awkward).
Seeing as I'm loading a web page I took take a look at UIWebView
too. It looks like UIWebView
may be the way to go. stringByEvaluatingJavaScriptFromString:
seems like a very handy way to extract the data and would allow the javascript to be stored in a separate file that would be easy to edit if the HTML changed. However, using UIWebView
seems a bit hacky (seeing as UIWebView
is a UIView
subclass it may block the main thread, and the docs say that the javascript has a limit of 10MB).
Does anyone have any advice regarding parsing XML/HTML before I get stuck in?
UPDATE:
I wrote a blog post about my solution:HTML parsing/screen scraping in iOS
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…