Skip to content

Instantly share code, notes, and snippets.

@tombatron
Created August 24, 2012 02:39
Show Gist options
  • Save tombatron/3444926 to your computer and use it in GitHub Desktop.
Save tombatron/3444926 to your computer and use it in GitHub Desktop.
Javascript fragment used to display all pictures on my baby's blog.
(function ($) {
"use strict";
var nextLinkRegex = /<a.* href='(.*)'>Older Posts<\/a>/g,
picturesRegex = /<a.*><img.*><\/a>/g,
$babyPictureList = $('#baby_pictures');
(function scrapePictures(url) {
var nextUrl = null;
$.get(url, function(response) {
var pictureMatch,
nextLinkMatch;
while(pictureMatch = picturesRegex.exec(response)) {
$babyPictureList.append(
'<li' + '>' + pictureMatch + '<' + '/li>'
);
}
nextLinkMatch = nextLinkRegex.exec(response);
if (nextLinkMatch) {
return scrapePictures(nextLinkMatch[1]);
}
});
}('/search/label/Baby%20Pictures'));
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment