$ curl -o 1.weather.html 'https://www.wunderground.com/weather/us/or/portland'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 847k 0 847k 0 0 487k 0 --:--:-- 0:00:01 --:--:-- 487k
$
####
$ ./1.wund_wind.pl
N5
$ cat 1.wund_wind.pl
#!/usr/bin/env perl
use 5.016;
use HTML::TreeBuilder;
my $tree = HTML::TreeBuilder->new_from_file('1.weather.html') or die;
my $wind = $tree->look_down(
_tag => 'div',
class => qr/^condition-wind /,
);
say $wind->as_trimmed_text( extra_chars => '\xA0' );
$
##
##
#!/usr/bin/env perl
use Mojo::UserAgent;
use 5.016;
use warnings;
# Fetch website
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;
my $res = $ua->get('1.weather.html')->result;
# Visit all nodes recursively to extract more than just text
for my $n ($res->dom->descendant_nodes->each) {
# Text or CDATA node
print $n->content;
# Also include alternate text for images
print $n->{alt} if $n->type eq 'tag' && $n->tag eq 'img';
}
##
##
$ ./1.mo_tree.pl
Can't connect: Name or service not known at ./1.mo_tree.pl line 9.
$