#!/usr/bin/perl use strict; use warnings; use 5.010; use Web::Scraper; use HTTP::Tiny; use utf8::all; use Encode; my $url = 'http://www.wetter.at/wetter/oesterreich/tirol/obsteig'; my $response = HTTP::Tiny->new->get($url); # don't die. the server returns 500 _and_ a valid content. # die "Failed to get '$url'.\n" unless $response->{success}; my $body = $response->{content}; my $s = scraper { process "div.dayInfo", "dayInfo" => "TEXT"; process "span.sunUp", "sunUp" => "TEXT"; process "span.sunDown", "sunDown" => "TEXT"; process "div.boxNow", "boxNow" => scraper { process "div.title", "title" => "TEXT"; process "div.temp", "temp" => "TEXT"; process "div.icontext", "icontext" => "TEXT"; process "div.rain", "rain" => "TEXT"; }; }; my $res = $s->scrape($body); my $timeregexp = qr/^.*?([0-9:]+).*?$/; ( my $date = $res->{dayInfo} ) =~ s/^.*, (\d+)\.(\d+)\.(\d+)$/$3-$2-$1/; ( my $time = $res->{boxNow}->{title} ) =~ s/$timeregexp/$1/; ( my $sunup = $res->{sunUp} ) =~ s/$timeregexp/$1/; ( my $sundown = $res->{sunDown} ) =~ s/$timeregexp/$1/; ( my $temp = $res->{boxNow}->{temp} ) =~ s/Â?°//; # real °, and "something" before?! my ( $weather, $clouds ) = $res->{boxNow}->{icontext} =~ m|^([^(]+)\((\d+)% .*$|; my ( $rain, $wind ) = $res->{boxNow}->{rain} =~ m|Niederschlag: (.+)Wind: (.+)|; $weather = decode( "utf8", $weather ); # debug if (0) { say 'Wetter in Obsteig (von wetter.at)'; say '---------------------------------'; say "Datum:\t$date"; say "Zeit:\t$time"; say "Sonne↑:\t$sunup"; say "Sonne↓:\t$sundown"; say "Temp:\t$temp°C"; say "Nied.:\t$rain"; say "Wind:\t$wind"; say "Wetter:\t$weather"; say "Bewölk:\t$clouds%"; say ''; } say "$date;$time;$sunup;$sundown;$temp;$rain;$wind;$weather;$clouds"; __END__ =head1 NAME wetter.at.pl - show weather information about Obsteig from wetter.at =head1 COPYRIGHT AND LICENSE Copyright 2017-2018, gregor herrmann Released under the same terms as Perl 5.