Ruby gem that automates HTTP sessions with sites: cookies, redirects, links, forms, and visit history.
Overview
Mechanize is a Ruby library aimed at scripting interaction with websites. It stores and sends cookies, follows redirects, can follow links and submit forms, populate fields, and keep a history of visited sites.
It depends on Ruby 2.6 or newer and several supporting gems for HTTP, cookies, parsing, and related concerns. Getting started material is provided in bundled guide and example documents.
The Ruby version was influenced by the Perl WWW::Mechanize module. Developers install it as a gem dependency and use it inside Ruby programs rather than as a standalone application.
Key features
- Automatic cookie handling
- Redirect following
- Link navigation
- HTML form fill and submit
- Visit history tracking
- Built-in testing helpers
Use cases
- Script login and form submission flows
- Crawl linked pages in Ruby
- Automate repetitive web tasks in tests
- Maintain state across HTTP requests