Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 使用FileUtils将WWW::Mechanize::File保存到磁盘_Ruby_Mechanize - Fatal编程技术网

Ruby 使用FileUtils将WWW::Mechanize::File保存到磁盘

Ruby 使用FileUtils将WWW::Mechanize::File保存到磁盘,ruby,mechanize,Ruby,Mechanize,在Ruby中使用Mechanize,我使用agent.get('http://example.com/foo.torrent“),使用FileUtils或其他方式,如何将此文件保存到硬盘驱动器(例如,在脚本运行的目录中) 另外,class=>WWW::Mechanize::File嗯,WWW::Mechanize::File有一个另存为实例方法,所以我想类似的方法可能会起作用: agent.get('http://example.com/foo.torrent').save_as 'a_file

在Ruby中使用Mechanize,我使用
agent.get('http://example.com/foo.torrent“)
,使用FileUtils或其他方式,如何将此文件保存到硬盘驱动器(例如,在脚本运行的目录中)


另外,
class=>WWW::Mechanize::File

嗯,
WWW::Mechanize::File
有一个
另存为
实例方法,所以我想类似的方法可能会起作用:

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

请注意,
Mechanize::File
类不是最适合大文件的。在这种情况下,应该改用
Mechanize::Download
类,因为它会将内容分小块下载到磁盘上。该文件将下载到脚本运行的位置(尽管您也可以指定不同的路径)。您需要首先设置默认解析器、创建新的解析器或修改现有解析器。然后,将其保存到所需路径:

agent.pluggable_parser.default = Mechanize::Download
agent.get( "http://example.com/foo.torrent}").save("path/to/a_file_name")
查看和以了解更多详细信息。另外,Stackoverflow中也有类似的问题