Image Scrape

Image Scrape


This script will scrape every image from the page at a user-supplied URL. The image files will include data residing on the host machine in addition to images linked from other web servers.

The Code

 require "open-uri"
 require "pathname"

 unless ARGV[0]
     puts "You must supply a URL to scrape images."
     puts "USAGE: ruby imageScrape.rb <url to scrape>"

 url = ARGV[0].strip

     open(url, "User-Agent" => "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)")
 do |source|
         source.each_line do |x|
 if x =~ /<img src="(.+.[jpeg|gif])"\s+/ ...

Get Wicked Cool Ruby Scripts now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.