iPhone: random "image of the day" type service? - iphone

The iPhone makes it really simple to snarf down an image from the web; you can turn a URL into a UIImage in one line of code. So I'd like to enable my app (an educational puzzle game... my first!) to download some random images to make it more interesting and dynamic.
I thought about using Kodak's image of the day RSS feed, but I'm having quite a time figuring out how to parse it. Rather than being a simple list of image URLs, it seems to reference a bunch of "jhtml" URLs, which run Javascript to display the images in your RSS reader. Is this intentionally obfuscated, or am I missing some basic step to parse this?
I also tried the Astronomy Picture of the Day, via this RSS feed, but it's just the original page's HTML stuffed into CDATA... ugh.
So I guess this is really two questions:
Is there a simple way to parse these feeds to actually get at the JPG URLs on the iPhone?
Is there a better source for "picture of the day" type images?
PS: I'm using NSXMLParser, which I learned to use here.

I would recommend going with something that has an API, perhaps the Flickr "Interestingness" feed:
http://www.flickr.com/services/api/flickr.interestingness.getList.html
There is an objective-C library written to help with accessing Flickr but not sure if this API call is included:
http://github.com/lukhnos/objectiveflickr/tree/master

Related

Copying images in from anti-scraper websites. Google Docs handles it easily - anyone know how?

I've been playing around with making a draftjs plugin that lets the user paste in mixed text&image content from websites and have images auto-uploaded to the server. I've quickly come to the realization that it's not easy, simply because of how many different sites use different kinds of counter-measures for copy/pasting images. Standard image tags in page content are no problem - easily grab the src and handle the file upload from the url. However, many sites use all kinds of trickery to make this a pain. For example, some will only serve small thumbnails, requiring a GET request on the image with a hash key in order to retrieve a larger version. Others somehow seem to corrupt the image so that it's unreadable by the time it's been retrieved. Others still play with weird embed tags to mess with draftjs' image blocks.
But then I open up a Google Docs file, and find that when I copy any images into that from a website, there's never any troubles whatsoever. All the problematic websites that I'm finding myself having to write specific methods for retrieving from seem to be handled by Google Docs with ease.
Am I using completely the wrong approach by trying to retrieve images from a url? Does Google use a far superior approach (yes, I presume) - in which case, does anyone have any idea what that approach might be?

How to extract data from a web site and format to raw text - iPhone Dev

I have been looking around for a while and not found anything useful, also not sure if I have worded the question in the clearest fashion so apologies
I have a section of an app I am building called 'Company News'. The company in question has a news page on their website which displays a title, an excerpt of text and a read more option.
At the minute in the iPhone application I just have a UIWebView which links to that URL, displays an error if no connection is available. However, if my user clicks a story to read the news obviously it opens up a new page, I want to avoid having to build in 'back' and 'forward' buttons and stay away from it looking like a browser within the app.
With that said, I am looking for a way to just extract that data from the website and just display it in my app as raw text. I am not particularly bothered about rich text formatting or anything fancy. I would just like the title and body of text.
Is this possible?
In essence, then, you are looking for an HTML parser.
Assuming the HTML you wish to parse has a predictable format, the approach I would take is to load the HTML via whatever URL loading system you want - e.g. NSURLConnection, ASIHTTPRequest, etc.
Then you will need to parse the raw HTML. I use XPath. It requires that you learn the syntax, but it should work.
For more details about how you might use XPath for parsing HTML, see the second response to this question. You will need to link to libxml2 in your project then use XPath to extract the nodes of interest.
Scraping web pages in this way is fragile, though, because it depends on the structure of a page you don't control and which could be changed unpredictably.

RSS feed only displays text

I have an rss reader app which works perfectly on some feeds, but on others it just displays text and no images.
Is it the feed which should be adjusted to publish images or Im sure it is something with the way I read the stream.
Why does it work for some streams(shows entire posts, images, videos etc. from e.g. blogspot rss feeds) but not for other rss feeds?
I have read that the stream itself can be set to publish different content amounts.
How can I parse the feed so that all feeds will work correctly?
It's very likely that it's due to the feed themselves... and not to the reader app.
Feed publisher can decide whether they want to include all or parts only of their content in their feeds (RSS or Atom).
Then, even if they publish all the content, they may decide to publish it as raw text (just the text content) or full XHTML, which would allow the inclusion of images.
Unfortunately, there is little that you can do, except maybe ask the developer of your app to allow to show the original site/page and not just the feed entries.
Ok, so what are the differences between the feeds that work and the feeds that don't? What assumptions do you make about the RSS content, and in what situations are those assumptions not satisfied? When you run the code in the debugger, what do you see when you encounter a feed where images don't work? Also, what code? ;)

Displaying content from an RSS feed in an iphone app

I have seen some tutorials on the subject, but they all go half into it and then leave a person wondering.
How can I stream an rss feed into an iphone app.
I know the xml should be read in, parsed etc.
But then I am not sure how to display the information I need like, images, embedded videos etc.
If someone could just point me in the right direction I would be extremely grateful.
Thanks in advance
First, you need some type of XML parser. You can use the built in NSXMLParser or a slew of other parsers that you will need to download. Each have their pros/cons depending on what type of reading/writing you will be doing with your RSS feed.
To display the data, I would recommend a tableView. You can create custom UITablvewCells for each cell to hold the data however you want to display it. There are several tutorials available for that if you want to Google for it.
As for data, read all the RSS data into an array you create and have the tableView access that array.
Again, there are many online tutorials for this already but it seems like you need help with displaying the data. A quick Google lookup for how to create custom UITableViewCells should provide you lots of helpful links. Good luck.

iPhone RSS Reader -- parseXML won't Load some XML feeds

I am using the SIMPLE RSS reading example found at http://theappleblog.com/2008/08/04/tutorial-build-a-simple-rss-reader-for-iphone/
It uses parseXML to load the RSS feeds.
Here is the problem I am having. For the following RSS feed example, I am having trouble getting it to load the feed. Comes up with an error that it cannot connect. However on my Mac RSS Reader it works fine, so I know the link is good.
Any ideas on why it cannot load this particular feed but it can load others fine?
http://www.okstate.com/rss.dbml?db_oem_id=200&media=news
Thanks.
I've just released an open source RSS/Atom Parser for iPhone and hopefully it might be of some use.
I'd love to hear your thoughts on it too!
In my experience, HTML markup causes an RSS parser to fail in most cases. I've experienced a problem like this with a lot of parser classes I've come across (in search of the ultimate one, which I didn't find)
My guess is that entities such as
's
are responsible for your crash. That was usually the case with my crashes. This also lead to my decision to create a 'proxy server' to pre-parse the XML before sending it to the iPhone (which gives me the advantage of caching, scaling, and some other stuff). I do believe there are solid solutions out there, but is always difficult writing a parser for so many RSS implementations.
P.S: W3C validates this feed as 'valid', so it really is 'our' problem..
Your problem could lie with:
Unicode characters (i.e. I see some o's with two dots above them in the feed)
The code you have doesn't respect CDATA sections correctly
To find out which is the case, save the feed file to your local disk and load it via your code to make sure the error happens.
Do a binary search on the file to find out if a particular RSS entry is causing the problem (i.e. remove all but the first rss entry and see if the problem exists. If it does, then the problem is there, if it doesn't put half the rss entries back in the file and repeat)
I've been experiencing a similar issue. I haven't yet pinned down the answer, but I've noticed that RSS 2 tends to parse more successfully than the rest.
There are many RSS feeds that contain invalid XML, usually because they were hacked together on the server side using HTML templates by somebody who didn't understand XML. I've seen improperly escaped (or non-escaped) HTML post contents, missing close tags, badly nested tags, and so on.
If you want to be able to parse arbitrary feeds, you have to clean up bad XML. The usual way is to use the "htmlTidy" library, which is included in the OS. This can clean up XML as well as HTML.
This example you're following uses NSXMLParser -- I have no idea why. It's a lower-level API and it doesn't support tidying. I would suggest using NSXMLDocument instead. There's a flag in that API that will tell it to use tidy when parsing the XML. This API also returns you the XML as a handy tree of elements that's easy to work with.