【发布时间】:2014-03-18 01:57:24
【问题描述】:
鉴于下面的NSString最初是从使用NSXMLParser解析XML文档中检索到的CData对象转换而来的,我如何获得这本书的以下属性:标题、书籍图片封面、作者、价格, 和评分?
这是我获取以下属性的基本解决方案
书名 - 我可能可以通过查看
riRssTitlespan 类来获得这个,但是我必须弄清楚如何读取 ahref url 标签之间的标题获取标题图书图片 - 我必须获取第一个 URL
http://ecx.images-amazon.com/images/I/41Lg22K3ViL._SL160_PIsitb-sticker-arrow-dp,TopRight,12,-18_SH30_OU02_.jpg,然后将所有内容保留到http://ecx.images-amazon.com/images/I/41Lg22K3ViL,省略其余部分,然后附加.jpg标签以后有一个完整的图片检索网址。图书作者 - 我必须按照与第 1 步相同的步骤,但要搜索
riRssContributorspan 标签。图书价格 - 这里没有所有商品通用的价格标签,但我确实看到的一个共同点是价格总是在
font tag中坐在BOLD tag。Rating - 大概可以通过查找包含单词
stars的URL然后抓取它后面的数字来检索,4表示4星,任何数字加上-5意味着额外的 0.5 星。所以3-5意味着 3.5 颗星。
在不弄乱的情况下,最好的方法是什么?此外,如果亚马逊决定更改其显示 URL 的方式,我也不喜欢我的代码会如何中断,我的应用程序依赖于亚马逊维护其 url 命名约定。
目前,这是最好的前进方式吗?有没有可以实现我想做的快速解析器?
这是亚马逊 RSS 提要的示例:http://www.amazon.co.uk/gp/rss/bestsellers/books/72/ref=zg_bs_72_rsslink
这是我为每个项目检索到的以下 CData NSString 数据。
<div style="float:left;">
<a class="url" href="http://www.amazon.co.uk/Gone-Girl-Gillian-Flynn/dp/0753827662/ref=pd_zg_rss_ts_b_72_9">
<img src="http://ecx.images-amazon.com/images/I/41Lg22K3ViL._SL160_PIsitb-sticker-arrow-dp,TopRight,12,-18_SH30_OU02_.jpg" alt="Gone Girl" border="0" hspace="0" vspace="0" />
</a>
</div>
<span class="riRssTitle">
<a href="http://www.amazon.co.uk/Gone-Girl-Gillian-Flynn/dp/0753827662/ref=pd_zg_rss_ts_b_72_9">Gone Girl</a>
</span>
<br />
<span class="riRssContributor">
<a href="http://www.amazon.co.uk/Gillian-Flynn/e/B001JP3W46/ref=ntt_athr_dp_pel_1">Gillian Flynn</a>
<span class="byLinePipe">(Author)</span>
</span>
<br />
<img src="http://g-ecx.images-amazon.com/images/G/02/x-locale/common/icons/uparrow_green_trans._V192561975_.gif" width="13" align="abstop" alt="Ranking has gone up in the past 24 hours" title="Ranking has gone up in the past 24 hours" height="11" border="0" />
<font color="green">
<strong></strong>
</font> 674 days in the top 100
<br />
<img src="http://g-ecx.images-amazon.com/images/G/02/detail/stars-4-0._V192253865_.gif" width="64" height="12" border="0" style="margin: 0; padding: 0;"/>(5704)
<br />
<br />
<a href="http://www.amazon.co.uk/Gone-Girl-Gillian-Flynn/dp/0753827662/ref=pd_zg_rss_ts_b_72_9">Buy new: </a>
<strike>£9.07</strike>
<font color="#990000">
<b>£3.85</b>
</font>
<br />
<a href="http://www.amazon.co.uk/gp/offer-listing/0753827662/ref=pd_zg_rss_ts_b_72_9?ie=UTF8&condition=all">60 used & new</a> from
<span class="price">£2.21</span>
<br />
<br />(Visit the
<a href="http://www.amazon.co.uk/Best-Sellers-Books-Crime-Thrillers-Mystery/zgbs/books/72/ref=pd_zg_rss_ts_b_72_9">Bestsellers in Crime, Thrillers & Mystery</a> list for authoritative information on this product's current rank.)
【问题讨论】:
-
谁能给我一些指导?
-
有一天,有人告诉我:stackoverflow.com/questions/1732348/…
-
@JJBoursier 我昨天遇到了这个。这是一个有趣的阅读。不过,我的解决方案不需要用正则表达式来解决。
-
如果是 XML,您是否考虑过使用 XPath?
-
您能否使用服务器端技术(正确的 JSON/XML 将发送到设备,但必须在服务器上完成)。
标签: html ios objective-c xml parsing