From: Dan Mansfield Date: 2010-09-16T05:16:08+09:00 Subject: Re: Mechanize file save on generated link Mike Dalessio wrote: > On Sun, Sep 12, 2010 at 5:54 PM, Dan Mansfield > wrote: > >> C:/ruby/test.rb:27:in `[]': can't convert String into Integer >> (TypeError) >> from C:/ruby/test.rb:27:in `block in
' >> from C:/ruby/test.rb:26:in `open' >> from C:/ruby/test.rb:26:in `
' >> >> what is the proper method to see the response back from clicking the >> link? >> > > links_with returns an array. Try using .first to pick out the first > result, > so: > > link = invoice_page.links_with(:href => "/be-portal/downloadPdf").first Ok, so some progress: invoice_page = agent.get(URL_BILLING) link = invoice_page.links_with(:href => "/be-portal/downloadPdf").first page = agent.click(link) #pp page File.open('myfile.pdf', 'w+') do |file| file << page end If I look at the content of page now it contains the stream of PDF data as well as: @code="200", @filename="Invoice_14051844_08/09/2010.pdf", @response= {"date"=>"Wed, 15 Sep 2010 19:13:04 GMT", "server"=>"Apache", "expires"=>"Wed, 15 Sep 2010 19:14:04 GMT", "cache-control"=>"max-age=60", "content-disposition"=> "attachment;filename=Invoice_14051844_08/09/2010.pdf", "vary"=>"Accept-Encoding", "content-encoding"=>"gzip", "content-length"=>"7950", "keep-alive"=>"timeout=5, max=92", "connection"=>"Keep-Alive", "content-type"=>"application/octet-stream"}, @uri= #> -- Posted via http://www.ruby-forum.com/.