No commit activity in last 3 years
No release in over 3 years
Mechanize-Progressbar provides ProgressBar for Mechanize#get and Link#click.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

> 1.0.0
> 1.5.2
>= 0
>= 0
>= 2.4.2
> 2.3.0
>= 1.6.1

Runtime

>= 1.0.0
>= 0.9.0
 Project Readme

mechanize-progressbar¶ ↑

Mechanize-Progressbar provides ProgressBar when you use Mechanize#get/Page#click. HTTP response only. HTTP requests are not supported.

you can do¶ ↑

script:

require 'mechanize'
require 'mechanize/progressbar'
agent = Mechanize.new
agent.progressbar{ agent.get(large_file) }

$stderr output:

http://host/large_file.zip
15% |ooooooo                        | 135.2KB  21.9KB/s ETA:  00:00:10

Requirements¶ ↑

  • Ruby 1.8.6 or later

  • recent Rubygems

  • Mechanize gem (1.0.0, 2.0)

  • ProgressBar gem

USAGE¶ ↑

Get file in Mechanize#progressbar block.

require 'mechanize'
require 'mechanize/progressbar'
agent = Mechanize.new
agent.progressbar{ agent.get(large_file) }

Link#click also works.

agent = Mechanize.new
agent.get(some_page)
agent.progressbar do
  agent.page.link_with(:text => 'download here').click
end

config ProgressBar¶ ↑

If you want to modify ProgressBar object, set options to argument.

pbar = ProgressBar.new(@title, @total, @out)
pbar.format = @format
pbar.format_arguments = @format_arguments

is

agent = Mechanize.new
agent.progressbar(
  :title => @title,
  :total => @total,
  :out => @out,
  :format => @format,
  :format_arguments => @format_arguments
){ agent.get(large_file) }

Mechanize-Progressbar prints the URL to $stderr before progressbar.

script:

agent.progressbar{ agent.get(large_file) }

output:

http://uri.host/large_file.zip
15% |ooooo                           | 135.2KB  21.9KB/s ETA:  00:00:10

If you do not want the “two-line mode”, set (:single => true).

script:

agent.progressbar(:single => true){ agent.get(large_file) }

output:

uri.host:   15% |ooo                 | 135.2KB  21.9KB/s ETA:  00:00:10

When Mechanize Logger output is same to ProgressBar (i.e, agent.log=Logger.new($stderr)), Mechanize::ProgressBar stops showing socket read log.

script:

agent.log = Logger.new($stderr)
agent.progressbar{ agent.get(large_file) }

output:

http://uri.host/large_file.zip
100% |ooooooooooooooooooooooooooooooo| 1024.0KB  21.9KB/s Time:  00:00:20
D, [...] DEBUG -- : Read 102400 bytes

LARGE FILE DOWNLOAD NOTE¶ ↑

Mechanize keeps all the got files as String object. When you get the five 100MB files, Mechanize uses at least 500MB memory.

If you wish to run Mechanize with minimum memory usage, try

agent.max_history = 1

Licence¶ ↑

MIT

alike Mechanize.

Author¶ ↑

kitamomonga kitamomonga@gmail.com d.hatena.ne.jp/kitamomonga/ (Japanese)