$ ./2.1.dom.pl ./2.1.dom.pl navSearch-searchState suggestion-search-container nav-search-form navbar-search-category-select navbar-search-category-select-contents suggestion-search suggestion-search-button imdbHeader-searchClose imdbHeader-searchOpen Can't locate object method "find" via package "Mojo::UserAgent" at ./2.1.dom.pl line 48. $ cat 2.1.dom.pl #!/usr/bin/perl use strict; use warnings; use Log::Log4perl; use 5.016; use Mojo::DOM; use Mojo::UserAgent; use Mojo::URL; use Mojo::Util qw(trim); my $log_conf3 = "/home/hogan/Documents/hogan/logs/conf_files/3.conf"; my $log_conf4 = "/home/hogan/Documents/hogan/logs/conf_files/4.conf"; #Log::Log4perl::init($log_conf3); #debug Log::Log4perl::init($log_conf4); #info my $logger = Log::Log4perl->get_logger(); $logger->info("$0"); # represent $0 as browser to server my $uaname = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36'; my $ua = Mojo::UserAgent->new; $ua->max_redirects(5)->connect_timeout(20)->request_timeout(20); $ua->transactor->name($uaname); ## main page of imdb contains search box my $imdburl = "http://www.imdb.com/"; ## example from https://docs.mojolicious.org/Mojo/DOM my $dom = $ua->get($imdburl)->res->dom; # say "$dom"; works # my @ids = $dom->find('[id]')->map( attr => 'id' )->each; #$logger->info("@ids"); my @matches = grep { /search/ } @ids; $logger->info("@matches"); my $vid = 'Virgin River'; $ua->post( $imdburl => form => { 'suggestion-search' => $vid } ); # assume first match my $filmurl = $ua->find('a[href^=/title]')->first->attr('href'); # extract film id my $filmid = Mojo::URL->new($filmurl)->path->parts->[-1]; # get details of film $dom = $ua->get("https://www.imdb.com/title/$filmid/")->res->dom; # print film details say trim( $dom->at('div.title_wrapper > h1')->text ) . ' (' . trim( $dom->at('#titleYear > a')->text ) . ')'; # print actor/character names foreach my $cast ( $dom->find('table.cast_list > tr:not(:first-child)')->each ) { say trim ( $cast->at('td:nth-of-type(2) > a')->text ) . ' as ' . trim( $cast->at('td.character')->all_text ); } __END__ $