Overview To Mechanize
jigarshah8055
Posted on February 20, 2024
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.
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.
- http://ruby.bastardsbook.com/chapters/mechanize/
- https://readysteadycode.com/howto-scrape-websites-with-ruby-and-mechanize
Complete Code On Github
Posted on February 20, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.