Save IO object to a file on Ruby
Im scraping a website using Celerity gem and I want to save an image but I dont know how t开发者_如何学运维o do it XD
With the next Celerity command I get an IO object
irb(main):260:0* image = @browser.image(:xpath, ".//*[@class='notdTop']/img").download
=> #<IO:0x277e07ae>
How can I save this object to a jpg file?? I tried this, but didnt work:
irb(main):261:0> image.flush
IOError: not opened for writing
but the IO object is not closed because I got this:
irb(main):264:0> image.closed?
=> false
Anyone can help me please?
Try:
image.save(filename)
http://rubydoc.info/gems/celerity/0.8.9/Celerity/Image#save-instance_method
精彩评论