问题描述
我正在使用Mechanize来方便某些文件的下载.目前,我的脚本使用以下行来实际下载文件...
I'm using Mechanize to facilitate the downloading of some files. At the moment my script uses the following line to actually download the files...
agent.get('http://example.com/foo').save_as 'a_file_name'
但是,这会将整个文件下载到内存中,然后再将其转储到磁盘中.您如何绕过此行为,而直接将其直接下载到磁盘?如果我需要使用WWW:Mechanize以外的其他功能,那我该如何使用WWW:Mechanize的cookie?
However this downloads the complete file into memory before dumping it to disk. How do you bypass this behavior, and simply download straight to disk? If I need to use something other than WWW:Mechanize then how would I go about using WWW:Mechanize's cookies with it?
推荐答案
您真正想要的是Mechanize :: Download
What you really want is the Mechanize::Download
http://mechanize.rubyforge.org/Mechanize/Download.html
您可以使用这种方式:
require 'mechanize'
agent = Mechanize.new
agent.pluggable_parser.default = Mechanize::Download
agent.get('http://example.com/foo').save('a_file_name')
这篇关于使用WWW:机械化将文件下载到磁盘,而无需先将其全部加载到内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!