Created
October 11, 2010 06:59
-
-
Save tota/620148 to your computer and use it in GitHub Desktop.
fetch images from imagegateway with watir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# fifi.rb: fetch images from imagegateway (CANON iMAGE GATEWAY) | |
# | |
# Copyright (C) 2010 TAKATSU Tomonari <tota@rtfm.jp> | |
# Distributed under the modified BSD license | |
# | |
require 'rubygems' | |
require 'watir' | |
require 'open-uri' | |
if ARGV.size != 2 | |
STDERR.print "Usage: #{File.basename($0)} url password\n" | |
exit(-1) | |
end | |
url = ARGV[0] | |
passwd = ARGV[1] | |
#Watir::Browser.default = 'firefox' | |
b = Watir::Browser.new | |
b.goto(url) | |
b.text_field(:name, 'password').set(passwd) | |
b.link(:xpath, "/html/body/form/div/div/div/table/tbody/tr/td/table[2]/tbody/tr/td[2]/div/a").click # ie | |
b.link(:xpath, "//img[@src='/ph/OPA/image/menu_btn_download.gif']/..").click | |
b.link(:xpath, "/html/body/form/div/div[3]/div/div[4]/a").click | |
1.step(b.div(:id, "column_AEGI_F03").divs.length/3) {|index| | |
f = b.div(:class => "photoThumbnailMargin", :index => index).div(:index, 2).p(:class, "imgName").text | |
b.cell(:class => "thumbnailSS", :index => index).image(:alt, "").click | |
case Watir::Browser.default | |
when 'ie' | |
w = Watir::Browser.attach(:title, '') | |
when 'firefox' | |
sleep 3 | |
w = Watir::Browser.attach(:title, /jpg/) # hard-coded temporarily | |
else | |
w = Watir::Browser.attach(:title, '') # not tested | |
end | |
File.open(f, "wb") {|f| f << open(w.url).read } | |
w.close | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment