質問

(Content-Typeヘッダに基づいた)画像の拡張子を取得する方法があり、それは体がワチールでは?

ここでは一例である

require 'watir'

zz = Watir::IE.new
zz.goto('http://flickr.com')
image = zz.image(:src => %r/l.yimg.com\/g\/images\//)
puts image

私は後者の画像の拡張とコンテンツ(base64encodedまたは一時ファイルのちょうど場所)を取得する必要がある

役に立ちましたか?

解決

require 'watir-webdriver'
require 'open-uri'
b = Watir::Browser.new :firefox

b.goto "http://altentee.com"
b.images.each do |img|
  uri = URI.parse(img.src)
  open(uri) { |file| puts file.content_type; open('/tmp/file', 'wb') { |tmp| tmp.write(file.read)}  }
end
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top