DEV Community

jigarshah8055
jigarshah8055

Posted on

Overview To Mechanize

This blog will guide you to the basic overview to use Mechanize using Ruby.

What is Mechanize?

  • Mechanize is a ruby gem(library) which is used to makes automated web interactions easy.
  • Mechanize is generally used for web scraping.

Why Mechanize?

  • It automatically send and store cookies, follow redirections and submit forms by populating form fields.
  • It also keeps tracks of visited sites as history.

Shall we begin?

Here I'm giving example by making a simple html page which have links and a form

  • First install the gem mechanize with below command.
    gem install mechanize

  • Make a html page with some links and form by submitting that form you'll redirect to google home page.

  • Here there are two links where home will redirect you to the current page and contact link will redirect you to contact page.

  • While you submit the given form by giving username then it'll go to google home page.

  • Now you have to make a ruby file and write below code in it.

  • This will give you the reference to basic operations like finding all links from web page, how to redirect to links, how to get form submit forms and how to get data of any web page.

You can find more information about mechanize from below blogs.

Complete Code On Github

Top comments (0)