I browsed the documentation Mechanize. The below is for .pdf only.
require 'mechanize'
agent = Mechanize.new
agent.pluggable_parser.pdf = Mechanize::FileSaver
agent.get 'http://example.com/foo.pdf'
- But can I also download .docx,.xlsx,.txt file also?
- when the file download will be done,what would be it’s default directory? Can we change the save file directory too?
- which browser would it select during downloading? Can we also change the browser control?
The type of file doesn’t matter; any file accessible over the net can be obtained via mechanize, which is a tool for automating interaction with Mechanize.
The file will be stored in the directory where the program was run. Use Mechanize::Download instead of
Mechanize::FileSaverto specify where the file should be downloaded to. Example code here: https://stackoverflow.com/a/9105153/429758 (Specify the full path in the filename)Mechanize doesn’t use a browser while downloading.
For all intents and purposes, Mechanize acts like a web browser with no user interfacevia http://ruby.about.com/od/tasks/a/The-Mechanize-2-0-Handbook.htmDo checkout the EXAMPLES page on mechanize documentation for further examples about how to use mechanize.