Web Scraping is the term used to define data extraction from website using programming. Perl is one of the most powerful and easy to use scripting language and Mechanize is one such package available in perl that makes web scraping possible. Using mechanize you can extract data from web by writing a simple program in perl.
Here is a code snippet to help you do web scraping using perl. To use below code, you need to download WWW-Mechanize package from here. Note that you might need to download some packages that WWW-Mechanize depends on before it works for you. This information is also provided on the link shared.
The code below fills an online form and prints the content of the page if login gets successful.
my $url = 'website address'; # update it appropriately
# Username for the login form - update it appropriately
$username = 'idno';
# Password for the login form - update it appropriately
$password = 'password';
my $mech = WWW::Mechanize->new(autocheck => 1);
$mech->get( $url );
# The field idno is obtained by looking at the source of login form in browser.
# It is the name of the text field username.
# The field pwd is obtained by looking at the source of login form in browser.
# It is the name of the text field password.
# The field B1 is obtained by looking at the source of login form in browser.
# It is the name of the button submit.
my $text = $mech->content();
Hope you find this information useful and easy to use. Please leave your suggestions or feedback in the comments section below. We always love to hear from our readers.