Friday, 17 October 2014

Test 20: Find name of director of movie from wikipedia website

Test:
Given a wikipedia page for any movie. Find the name of director of movie.

Learning: 
use of Mojo::DOM to read text of any tag
use /regex/s to consider space also, like /By director/ wont work but /By director/s will work



Solution:

use WWW::Mechanize;
use WWW::Mechanize::Link;
use Mojo::DOM;

my $m = WWW::Mechanize->new();
$m->get("http://en.wikipedia.org/wiki/Kal_Ho_Naa_Ho");


$c=$m->content();

(my $a) = $c =~ /Directed by(.*?\/a>)/s;

my $dom = Mojo::DOM->new($a);
print $dom->at('a')->text;

output snapshot:

No comments:

Post a Comment