Ruby · save_images

Save images from any URL

Save images from any URL

Note: it will works only OS –> WINDOWS and Browser –>  IE

1. install Ruby

2. Install watir gem – gem install watir

3. Look this code

Code:

require ‘watir’
include Watir
#browser = Watir::IE.new
browser=Watir::IE.new
browser.visible=true
browser.goto(‘http://www.misipile.com/’)

idx = 0

# using the images collection, iterate through all of the images on a page
browser.images.each do |x|
idx += 1
# apparently the string accepted by the string method will not allow variable substitution
original_type= x.src[-4,4]

type=”.gif” if original_type == ‘.gif’
type=”.jpg” if original_type == ‘.jpg’
type=”.png”if original_type == ‘.png’
type=”.bmp” if original_type == ‘.bmp’
type=”jpeg” if original_type == ‘.jpeg’

location = ‘C:\TML\fileq-‘ + idx.to_s + type
x.save(location)
end

4. Change the location whatever u want.

5. Go there ..

All the images in that folder .. Am I right ..?

comment are always welcome..