开发者

Save IO object to a file on Ruby

开发者 https://www.devze.com 2023-03-24 14:12 出处:网络
Im scraping a website using Celerity gem and I want to save an image but I dont know how t开发者_如何学运维o do it XD

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号