WWW::Mecha nize::Page #images
WWW::Mecha
1 require 'mechanize' 2 3 WWW::Mechanize::Page.class_evaldo 4 def images 5 @images ||= search('img').map do |img| 6 case src = img['src'] 7 when %r{^https?://} 8 src 9 else 10 (uri + src).to_s 11 end 12 end.uniq 13 end 14 end
forms, links では Page::XXX オブジェクトが返るので、
同様に Page::Imag
1 agent = WWW::Mechanize.new 2 page = agent.get('http://blog.s21g.com /') 3 page.forms.size # => 1 4 page.links.size # => 109 5 page.images.size # => 17
とりあえず快適!
posted by
maiha
on Fri 28 Aug 2009
at 09:47