I want to download this picture using Ruby. How do I do that?
http://farm1.static.flickr.com/92/218926700_ecedc5fef7_o.jpg
I am using Mac OS.
I want to download this picture using Ruby. How do I do that?
http://farm1.static.flickr.com/92/218926700_ecedc5fef7_o.jpg
I am using Mac OS.
Try using the Mechanize gem:
Start with:
sudo gem install mechanize
to install Mechanize.Then:
EDIT: To make things cleaner I would suggest you use the File's name itself when you save the image. I had an issue saving bulk images because they were not formated correctly. The images were saved like this:
Thats why you should probably use the image name as the file name like this:
File.basename takes the image url and just returns the the actual image name:
The same way you download anything else. Net::HTTP
If you want to download all the images on one page, you can use the image_downloader gem:
or
The easiest way would be to require
open-uri
and use that with the previous answer or use the also supplied Net::HTTP module with its get method.There is a gem called
down
which is simple to use.Firstly, install this gem by
gem install down
.Then:
You can read more on this gem in its github repo https://github.com/janko-m/down.