简体   繁体   中英

Rails Mechanize - download file

I have filled in a form which when submitted should trigger the downloading of a file. I tried saving the file in the following way:

mechanize.get(form.submit).save_as('file.csv')

However, this saves the page's source rather than a file.

How could I save the file when submitting the form?

You need Mechanize::Download .

require 'mechanize'

mechanize = Mechanize.new
mechanize.pluggable_parser.default = Mechanize::Download
# ... fill form
mechanize.get(form.submit).save('file.csv')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM