Given the NSString
below which was originally converted from a CData
object retrieved from parsing an XML document with NSXMLParser
, how can I obtain the following properties of the book: title, book image cover, author , price, and rating?
Here is my rudimentary solution for obtaining the following properties
Book Title - I could probably obtain this by looking at the
riRssTitle
span class, but then I would have to figure out how to read the title between the ahref url tag to obtain the titleBook Image - I would have to get by grabbing the first URL
http://ecx.images-amazon.com/images/I/41Lg22K3ViL._SL160_PIsitb-sticker-arrow-dp,TopRight,12,-18_SH30_OU02_.jpg
and then leaving everything up tohttp://ecx.images-amazon.com/images/I/41Lg22K3ViL
omitting the rest, and then appending the.jpg
tag to have a complete url for image retrieval at a later point.Book Author - I'd have to follow the same step as step 1 but instead searching for the
riRssContributor
span tag.Book Price - Here there is no price tag thats common across all items, one thing I do see in common though is that the price is always in a
font tag
where it then sits in aBOLD tag
.Rating - which can probably be retrieved by looking for the URL that contains the word
stars
and then grab the numbers that follow it,4
means 4 stars, any number with-5
appended to it means an extra .5 stars. so3-5
would mean 3.5 stars.
Whats the best way of doing this without it getting messy? Also I dont like how my code can break should Amazon decide to change the way it displays it's URLS, my app relies on amazon maintaining its url naming conventions.
For now though, is this the best way forward? Is there a quick parser that can achieve what I wish to do?
This is an example of an amazon RSS feed: http://www.amazon.co.uk/gp/rss/bestsellers/books/72/ref=zg_bs_72_rsslink
Here is the below CData NSString
data I retrieve for each item.
<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.)