Jomoka
Jomoka

Reputation: 157

iPhone html Parsing with libxml2 and hpple

I am trying to play around with html parsing and iPhone development.

Heres my question: Let say you have a textfield for the user to enter a value on a website. How do i send my own value to the textfield using libxml2 library and hpple? I want to enter a value in a textbox, and parse the results. Here is a visual representation of what I want to do:

https://dl.dropbox.com/u/42738601/Screen%20Shot%202012-11-24%20at%2010.07.45%20PM.png

Thanks in advance!

Upvotes: 3

Views: 587

Answers (1)

Rob
Rob

Reputation: 437632

Ray Wenderlich's How To Parse HTML on iOS tutorial covers the parsing portion of your question.

If you want to interact with a web page, there are two basic techniques.

  1. If the client-side portion of the web site isn't too complicated and if you've successfully deciphered the HTML to figure out what sort of GET and POST operations are in progress, you can create a NSURLConnection, make requests and, using the skills you've developed from Ray Wenderlich's tutorial, parse the responses. See Apple's URL Loading System Programming Guide. Also see the SimpleURLConnections demo for examples of simple POST and GET interactions. If your desired server interaction is a little more complicated, check out the appropriately named AdvancedURLConnections sample.

  2. Alternatively, you could let a UIWebView manage the interaction between your app and the web server. Thus you could, once the UIWebViewDelegate method webViewDidFinishLoad is called, you can probably then refer to this article about Injecting JavaScript Into a UIWebView, which discusses the UIWebView method stringByEvaluatingJavaScriptFromString.

Personally, I'd lean towards the first approach as it's likely to be more robust. Having said that, it's worth noting that interacting with servers by simulating web interfaces is suboptimal. It would far better if you could use a proper web service that delivered, for example, JSON or XML responses. I appreciate that you probably don't have that option (otherwise you probably wouldn't have asked the question), but we should acknowledge that the above approaches really are inherently fragile and inefficient.

Upvotes: 1

Related Questions