HTML 图像字符串解析器
我想知道是否有人对我的问题有任何想法。我需要从 UIWebView 加载的 html 文件中提取所有图像文件。我已将文件加载到 NSString 中,现在需要解析该文件。我已经使用 ComponentsSeparatedByString 创建了一个数组,搜索 .jpg、.gif 等。然后尝试向后移动以到达文件的开头。我最好的解决方案是能够将 html 解析为包含 img src="source" width="" height="" 等的 NSArray
任何帮助或提示将不胜感激。我最后的努力是对整个文件进行从左到右的搜索/替换,以找到我需要的字符串,但希望有一种更快的方法。
I was wondering if anyone had any ideas for my problem. I need to extract all the image files from a html file loaded by a UIWebView. I have the file loaded into a NSString and now need to parse the file. I have gone through creating an array with componentsSeparatedByString searching for .jpg, .gif, etc. Then trying to work backwards to get to the beginning of the file. My best solution would be to be able to parse out the html into an NSArray containing img src="source" width="" height="" etc
Any help or hints would be appreciated. My last ditch effort would be doing a search/replace left to right of the entire file to find the strings I need, but hope there is a quicker way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不解析 HTML,使用 libxml2。它具有广泛的面向 HTML 的解析/遍历功能,使您可以通过元素以编程方式导航文档。
我还没有面向 HTML 的示例代码可供使用,但这应该只是
htmlReadDoc()
获取解析后的文档;然后根据读取树示例调整您的遍历。Don't parse HTML, use libxml2. It has an extensive range of HTML-oriented parsing/traversing functions that let you navigate your document programmatically by elements.
I haven't got HTML-oriented sample code to work from, but it should just be a matter of
htmlReadDoc()
to get a parsed document; and then adapt your traversal from the read tree example.