Tuesday, 7 October 2014

Test 10: Find a url in webpage by keyword

Test:
Given a keyword, find all url having that keyword

Learning: 
 $m->find_all_links(
    tag => "a", text_regex => qr/keyword/i ); used to find keyword in url


Solution:

use WWW::Mechanize;
my $m = WWW::Mechanize->new();
$m->get( "http://www.google.com/" );

my @links = $m->find_all_links(
    tag => "a", text_regex => qr/history/i );


foreach(@links)
{
$tmp=$_->text;
print "$tmp\n";
$tmp=$_->url;
print "$tmp\n";
}


output snapshot:

No comments:

Post a Comment