获取 Web 目录中的图像 URL [英] Getting Image URLs in a Web Directory

查看:25
本文介绍了获取 Web 目录中的图像 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取所有图像的 URL,或者让我们说网络目录 (www.abcde.com/images) 中的JPEG"文件.我只想要他们的 URL 数组.. 我无法管理.你能帮我解决这个问题吗?

I want to get URLs of all images or lets say "JPEG" files in a web directory (www.abcde.com/images). I just want their URLs in an array.. I couldnt manage that. Could u pls help me with this?

提前致谢..

推荐答案

假设您可以访问索引文件,您可以简单地通过 NSURL 加载整个 html 文件并删除链接行.然而,当您想在更复杂的文档中搜索(蜘蛛或爬行")链接时,这将不起作用(或几乎不起作用).在 iOS 上,我建议您使用简单但功能强大的hpple"框架(https://github.com/topfunky/hpple).它用于解析html.您可以使用它搜索某些 html 元素,例如 结构.

Assuming you have access to an index file you could simply load via NSURL the whole html file and cut out the link lines. This however will not work (or hardly work) when you want to search ("spider or crawl") for links in more complex documents. On iOS i would suggest you use the simple, yet quite powerfull "hpple" framework (https://github.com/topfunky/hpple). It is used to parse html. You can search with it for certain html elements, such as <a href...> constructs.

带有 hpple 的示例可能如下所示:

a sample with hpple could looks like this:

NSURL *url = [NSURL URLWithString:@"whatver.com/images"];
NSData *data = [NSData url];
TFHpple *hppleParser = [TFHpple data];
NSString *images = @"//img"; // grabbs all image tags
NSArray *node = [hppleParser searchWithXPathQuery:images]

http://www.raywenderlich 上找到一个更大的例子.com/14172/how-to-parse-html-on-ios

这篇关于获取 Web 目录中的图像 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆