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 O
Try using the Mechanize gem:
Start with: sudo gem install mechanize
to install Mechanize.
Then:
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
link = 'http://www.asite.com/pic.jpg'
agent.get(link).save "images/pic.jpg"
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:
#pic.jpg(1)
#pic.jpg(2)
#etc.
Thats why you should probably use the image name as the file name like this:
agent.get(src).save "images/#{File.basename(url)}"
File.basename takes the image url and just returns the the actual image name:
File.basename("http://www.asite.com/pic.jpg")
# returns the image name
pic.jpg