Created
August 24, 2012 02:39
-
-
Save tombatron/3444926 to your computer and use it in GitHub Desktop.
Javascript fragment used to display all pictures on my baby's blog.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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