Ruby 如何使用Mechanize保存通过单击按钮下载的文件

Ruby 如何使用Mechanize保存通过单击按钮下载的文件,ruby,mechanize,Ruby,Mechanize,我尝试使用Mechanize模拟单击网页上的按钮,然后在浏览器中启动文件下载。这是我的代码片段 form = page.forms.first # => Mechanize::Form form = agent.page.form_with(:name => "aspnetForm") button = form.button_with(:value => "GPX file") pp button agent.submit(form, button) 这样显示pp按钮的

我尝试使用Mechanize模拟单击网页上的按钮,然后在浏览器中启动文件下载。这是我的代码片段

form = page.forms.first # => Mechanize::Form
form = agent.page.form_with(:name => "aspnetForm")

button = form.button_with(:value => "GPX file")
pp button

agent.submit(form, button)
这样显示pp按钮的输出,这意味着它是右侧按钮:

#<Mechanize::Form::Submit:0x89fe874
 @name="ctl00$ContentBody$btnGPXDL",
 @node=
  #(Element:0x44ff480 {
    name = "input",
    attributes = [
      #(Attr:0x44476d2 { name = "type", value = "submit" }),
      #(Attr:0x44476c8 {
        name = "name",
        value = "ctl00$ContentBody$btnGPXDL"
        }),
      #(Attr:0x44476be { name = "value", value = "GPX file" }),
      #(Attr:0x44476a0 { name = "id", value = "ctl00_ContentBody_btnGPXDL" })]
    }),
 @value="GPX file">
#
但是在发布了“agent.submit(form,button)”之后,我如何让Mechanize检索单击该按钮将发送到浏览器的文件

我进行了搜索,找到了获取网页或链接的方法,但没有找到任何适合这种情况的方法

顺便说一句,我对ruby和Mechanize都是一个完全的新手,如果这是一个愚蠢的问题,那么很抱歉,但是谢谢你的回答


M:

提交人应返回文件或页面:

response = agent.submit(form, button)
File.open('saved_file', 'wb'){|f| f << response.body}
response=agent.submit(表单,按钮)

open('saved_File','wb'){| f | f太棒了,这正是我所需要的,谢谢你!