Tuesday, 30 September 2014

Test 7: Get all links from a page and display their text and url addresses

Test:
Get all links from a page and display their text and url addresses

Learning: 
Use WWW::Mechanize
$m->links to get all links of a page


Solution:

use WWW::Mechanize;
my $m = WWW::Mechanize->new();
$m->get( "http://www.google.com/" );
@arr=$m->links;
$count=1;
foreach (@arr)
{
print "link $count--";
$count++;
print $_->text."\n\t".$_->url."\n\n" ;
}


output snapshot:

No comments:

Post a Comment