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.
-
$mytag="apes";
-
$flikker = join("",file("http://api.flickr.com/services/feeds/photos_public.gne?tags=$mytag&format=rss"));
-
$flikkerhits = preg_split('/img src="\;/', $flikker, -1, PREG_SPLIT_OFFSET_CAPTURE);
-
$i=0;
-
foreach($flikkerhits as $flikkerhit){
-
$i++;
-
if($i>1) echo "<img src=\"".substr($flikkerhit[0], 0, strpos($flikkerhit[0], 'width')-7)."\" />";
-
}
$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 [" 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.
…that is a cute ape