Download Many Images in One Line ::

January 26, 2013 at 2:50 pm EDT

I wanted to download all of these wallpapers http://www.autoblog.com/photos/mclaren-p1-paris-2012/full/#photo-5320785/ because quite frankly, it’s an awesome car. The fact of the matter is though, 45 images is quite a few. I used this one liner in Ruby to download all of them using wget:

1.upto(45) { |x| `wget http://autos.cpapi.aol.com/dl_image/download_image.php?file=http://www.blogcdn.com/www.autoblog.com/media/2012/09/#{“%02d” % x}-mclaren-p1-paris.jpg -O #{“%02d” % x}-mclaren-p1.jpg` }

Easy huh? ┬áThe “%02d” % x is used to pad ‘x’ with the correct number of 0’s. ┬áThis sort of thing can be applied to a lot of other pages given there is some kind of simple pattern like there was in this one.


No Comments