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


require ‘watir’
include Watir
#browser =

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

4. Change the location whatever u want.

5. Go there ..

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

comment are always welcome..


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s