简体   繁体   English

iPhone html解析libxml2和hpple

[英]iPhone html Parsing with libxml2 and hpple

I am trying to play around with html parsing and iPhone development. 我正在尝试使用html解析和iPhone开发。

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? 如何使用libxml2库和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 https://dl.dropbox.com/u/42738601/Screen%20Shot%202012-11-24%20at%2010.07.45%20PM.png

Thanks in advance! 提前致谢!

Ray Wenderlich's How To Parse HTML on iOS tutorial covers the parsing portion of your question. Ray Wenderlich的iOS如何解析HTML教程涵盖了问题的解析部分。

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. 如果网站的客户端部分不是太复杂,并且如果您已成功解密HTML以确定正在进行哪种GET和POST操作,您可以创建NSURLConnection ,发出请求,并使用你从Ray Wenderlich的教程开发的技巧,解析回应。 See Apple's URL Loading System Programming Guide . 请参阅Apple的URL加载系统编程指南 Also see the SimpleURLConnections demo for examples of simple POST and GET interactions. 另请参阅SimpleURLConnections演示 ,了解简单POST和GET交互的示例。 If your desired server interaction is a little more complicated, check out the appropriately named AdvancedURLConnections sample . 如果您希望的服务器交互稍微复杂一些,请查看相应名称的AdvancedURLConnections示例

  2. Alternatively, you could let a UIWebView manage the interaction between your app and the web server. 或者,您可以让UIWebView管理您的应用程序和Web服务器之间的交互。 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 . 因此,一旦调用UIWebViewDelegate方法webViewDidFinishLoad ,您就可以参考本文关于将JavaScript注入UIWebView的文章,该文章讨论了UIWebView方法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. 话虽如此,值得注意的是,通过模拟Web界面与服务器交互并不是最理想的。 It would far better if you could use a proper web service that delivered, for example, JSON or XML responses. 如果您可以使用提供JSON或XML响应的适当Web服务,那就更好了。 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. 我很欣赏你可能没有这个选择(否则你可能不会问这个问题),但是我们应该承认上述方法本质上是脆弱和低效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM