erdekhayser
erdekhayser

Reputation: 6657

RSS Get Image on Page

I have a collection of RSS feeds in my iOS app, and I need to get the main image to post alongside the title. The posts do not have any image or media:thumbnail elements to use. I have looked through all the elements that show up, and nothing else would give me an image or an image URL.

Is there any way to extract the main image of a page, or some other method, to get the thumbnail of the post?

Optimally, I would not want to have to load every single webpage to look at, because users on their data plan would not want that many pages loaded that they don't want to look at.

I am currently using KMXMLParser in my app.

Upvotes: 1

Views: 926

Answers (2)

Sony Mathew
Sony Mathew

Reputation: 2971

Actually I think it's easy to look for Open Graph image in the page. Usually most of the news or blog sites follows open graph protocol. There will be a meta tag og:image in the meta data of the page. It's easy to fetch and analyse this metadata of the page rather than fetching the whole page and finding the big and small images.

As an example, the following is the Open Graph protocol markup for The Rock on IMDB:

<html prefix="og: http://ogp.me/ns#">
<head>
<title>The Rock (1996)</title>
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
...
</head>
...
</html>

For more info on Open graph Protocol refer http://ogp.me/ Please remember that this won't work for all sites but most of the popular sites. So for those sites that dosen't follow this you have to find another way.

Upvotes: 1

E. Rivera
E. Rivera

Reputation: 10938

You could search for image URL's and then choose one of them (first you find?).

Most apps do that. Also I guess that's how Facebook chooses a thumbnail image when you share a link.

Alternatively you could download the images and choose the biggest, etc. Probably not worth the effort unless you pre-load images anyway.

Upvotes: 0

Related Questions