# JSON POST (application/json) with TLS certificate authentication
my $tx = $ua->cert('tls.crt')->key('tls.key')->post('https://example.c
+om' => json => {top => 'secret'});
[download]
####
#!/usr/bin/perl
use strict;
use warnings;
use Mojo::JSON qw(encode_json);
use feature 'say';
my $bytes = encode_json{ top => 'secret' };
say $bytes;
####
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use Mojo::URL;
use Mojo::Util qw(trim);
use Mojo::UserAgent;
my $imdburl = 'https://www.imdb.com/search/title?title=';
# prompt for title, replace spaces with plus signs
say 'Enter name of film to search for: ';
my $film = ;
chomp $film;
$film =~ s/ /+/g;
$imdburl .= $film;
# pretend to be a browser
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 );
# find search results
my $dom = $ua->get( $imdburl )->res->dom;
#my $dom = $ua->post( $imdburl => form => {title => $film} )->res->dom;
# assume first match
my $filmurl = $dom->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 'Search Results';
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 );
}
####
Enter name of film to search for:
Batman Begins
Search Results
Batman Begins (2005)
Christian Bale as Bruce Wayne /
Batman
Michael Caine as Alfred
Liam Neeson as Ducard
Katie Holmes as Rachel Dawes
Gary Oldman as Jim Gordon
Cillian Murphy as Dr. Jonathan Crane /
The Scarecrow
Tom Wilkinson as Carmine Falcone
Rutger Hauer as Earle
Ken Watanabe as Ra's Al Ghul
Mark Boone Junior as Flass
Linus Roache as Thomas Wayne
Morgan Freeman as Lucius Fox
Larry Holden as Finch
Gerard Murphy as Judge Faden
Colin McFarlane as Loeb