使用FileUtils将WWW :: Mechanize :: File保存到磁盘 [英] Save WWW::Mechanize::File to disk using FileUtils

查看:64
本文介绍了使用FileUtils将WWW :: Mechanize :: File保存到磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Ruby进行机械化时,我可以使用agent.get('http://example.com/foo.torrent'),FileUtils或其他方式获得某个文件,如何将该文件保存到硬盘驱动器(例如,在运行脚本的目录中)?

Using Mechanize with Ruby I get a certain file using agent.get('http://example.com/foo.torrent'), with FileUtils or otherwise, how do I save this file to my hard drive (for instance, in a directory wherefrom the script is running)?

P.S. class => WWW::Mechanize::File

推荐答案

好吧,WWW::Mechanize::File有一个save_as实例方法,所以我想类似的事情可能会起作用:

Well, WWW::Mechanize::File has a save_as instance method, so I suppose something like this might work:

agent.get('http://example.com/foo.torrent').save_as 'a_file_name'

这篇关于使用FileUtils将WWW :: Mechanize :: File保存到磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆