scrape rss flickr pics (one)

Today, ungodly ones, we scrape flickr-pics with php.

I first checked the normal tag-listing page and you can scrape that one as well but sometimes rss-files are easier. In this case the nice flickr people stuff the image link in a [description] or something, so I have to use preg_match anyway, otherwise i’d use simplexml.

The http://api.flickr.com/services/feeds/photos_public.gne rss-file has less obsolete stuff in it so I’ll use that one.

  1. $mytag="apes";
  2. $flikker = join("",file("http://api.flickr.com/services/feeds/photos_public.gne?tags=$mytag&format=rss"));
  3. $flikkerhits = preg_split('/img src=&quot\;/', $flikker, -1, PREG_SPLIT_OFFSET_CAPTURE);
  4. $i=0;
  5. foreach($flikkerhits as $flikkerhit){
  6.     $i++;
  7.     if($i>1) echo "<img src=\"".substr($flikkerhit[0], 0, strpos($flikkerhit[0], 'width')-7)."\" />";
  8. }

$mytag is the pictures tag I want
photos_public.gne is the public pictures file
I break up the rss text on [img src="]
that gives me a list starting with all image url’s
all image url parts end with [&quot width’]
so I do a strpos on “width”, and take 7 off
and I got my image url,
add an image tag and I got a basic dump of the images
the first string is crap, so i use a counter to exclude it.

a basic 7 lines flickr rss-scraper, short, I can handle that.

ape beasty …that is a cute ape

on to part two…

Posted in php, tool and tagged , .

Leave a Reply

Your email address will not be published. Required fields are marked *