Skip to content

Instantly share code, notes, and snippets.

@henrik
Created December 23, 2010 15:24
Show Gist options
  • Save henrik/753112 to your computer and use it in GitHub Desktop.
Save henrik/753112 to your computer and use it in GitHub Desktop.
Sothebys full-size image ripper.
#!/usr/bin/env ruby
# Sothebys full-size image ripper.
# Gets the full-size images from the lots listed after __END__.
# By Henrik Nyh <http://henrik.nyh.se> 2010-12-23 under the MIT license.
require "open-uri"
# We get an error page if we do not specify a user agent.
USER_AGENT = "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; Media Center PC 4.0; SLCC1; .NET CLR 3.0.04320)"
def read_url(url)
open(url, "User-Agent" => USER_AGENT).read
end
DATA.read.each_line do |url|
html = read_url(url)
image_base_url = html[%r{(http://s7d2\.scene7\.com/is/image/Sothebys/.+?)\?\$}, 1]
local_file = "/tmp/sothebys-#{File.basename(image_base_url)}.jpg"
# We're not allowed to request larger images than 4000 * 4000 px.
image_url = "#{image_base_url}?req=tile&rect=0,0,4000,4000"
File.open(local_file, "w") { |f| f.write read_url(image_url) }
# ImageMagick - trim background color around image
system("convert", local_file, "-trim", local_file)
puts "Done: #{local_file}"
end
__END__
http://www.sothebys.com/app/live/lot/LotDetail.jsp?lot_id=159428750
http://www.sothebys.com/app/live/lot/LotDetail.jsp?lot_id=159377074
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment