利用ruby批处理抓取图像

上一篇 / 下一篇  2010-12-24 12:15:32 / 个人分类:ruby+watir

watir底层中很多集合类代码如:buttons, divs, links, spans等等,方便用户用each方法来枚举。
例如下面代码,批 处理抓取页面中图片对象
把所有image生成保存到本地。
require 'watir'
browser = Watir::IE.new
browser.goto('http://twitter.com')
 
idx = 0
browser.images.each do |x|
  idx += 1
  location = 'c:\tmp\file-' + idx.to_s + '.jpg'
  x.save(location)
end

TAG:

 

评分:0

我来说两句

Open Toolbar