#!/usr/bin/env perl use utf8; use feature 'say'; use Mojo::UserAgent; my $data = undef; #Get correct file my $cache = shift // '/tmp/cache.html'; if(-d $cache){ die("'$cache' is folder. You need to use file."); } if(-e $cache){ $data = Mojo::File->new($cache)->slurp; }else{ say 'Fetching fresh HTML'; my $ua = Mojo::UserAgent->new; my $tx = $ua->get('https://www.mojolicious.org'); die "Could not fetch! Error is ", $tx->result->code unless($tx->result->is_success); $tx->result->content->asset->move_to($cache); $data = $tx->result->body; #->body is not only
..., but a complete loaded resource content for 1 file. } say "Tags are:\n\t", Mojo::DOM->new($data)->find('a')->map(attr=>'href')->uniq->sort->join("\n\t"); ####
Mojo::DOM->new($data)->find('a')->map(attr=>'*')->join("\n\t");
##
##
my %attrs = "Tags are:\n\t", Mojo::DOM->new($data)->attr;
map{ print "(%s)/(%s)\n", $_, $attrs{$_} } sort keys %attrs;
##
##
my $dom = Mojo::DOM->new($data);
map{ say } $dom->find('a')->first;
my $attrs = $dom->find('a')->first->attr;
map{ printf "(%s)/(%s)\n", $_, $attrs->{$_} } sort keys %$attrs;