iOS - 检索所有
的最快方法在 html 字符串中?
我有很多 HTML 字符串(来自 google reader 的新闻项目)需要处理。我主要需要做的是从 HTML 中检索所有 img 标签。
谁能告诉我最有效的方法?
谢谢
另外,如果我需要检索所有标签以及
标签怎么办?有什么最快的方法可以在一次运行中检索两个甚至多个标签?
谢谢
I have many HTML strings (news items from google reader) to process. Majorly what I need to do is to retrieve all img tags from the HTMLs.
Can anyone tell me a most efficient way to do that?
Thanks
Also, what if I need to retrieve all tags as well as
tags? Any fastest way to retrieve both or even more tags in one run?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设 HTML 字符串实际上是有效的 XML(即它们实际上是 XHTML),那么您应该考虑使用 XPath 来匹配名称为“IMG”的所有元素。我已经在 iOS 应用程序中使用了各种 C 库来成功地完成此类操作。
Assuming that the HTML strings are actually valid XML (i.e. they are actually XHTML), then you should consider using XPath to match all elements of the name "IMG". I've used various C libraries in an iOS application to do this kind of things successfully.
另一种尝试方法是使用 NSScanner 实例。假设您的 HTML 字符串位于名为 htmlString 的 NSString 中,您可以尝试如下操作:
Another approach to try would be to use an NSScanner instances. Assuming you have your HTML string in an NSString called htmlString, you could try something like this:
尝试 libtidy + NSXMLParser:
从文档中,
NSXMLDocumentTidyHTML
:在处理文档期间将 HTML 格式化为有效的 XHTML。如果这不起作用,您可以尝试加载 HTML 源进入 UIWebView 并使用 javascript 访问 DOM。
Try libtidy + NSXMLParser:
From the doc,
NSXMLDocumentTidyHTML
: Formats HTML into valid XHTML during processing of the document.If this doesn't work, you can try loading the HTML source into an UIWebView and use javascript to access the DOM.