Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: creating a webpage to fetch/calculate weather data

by Aldebaran (Curate)
on Jun 25, 2020 at 01:57 UTC ( [id://11118480]=note: print w/replies, xml ) Need Help??


in reply to Re: creating a webpage to fetch/calculate weather data
in thread creating a webpage to fetch/calculate weather data

Big day for perl and you, Util; I thought your presentation was awesome, but I could not ask any questions, as the only way I could hear anything was going to the livestream with youtube.

Then I hauled out an older machine with a newer ubuntu and now can hear the zoom proceedings. Maybe others had similar problems or not...I could be quite smart and be the local dunce in such matters.

I've always been interested in the weather and trees of every variety. bliako has posted several examples recently that are fascinating, but I had forgotten about HTML::TreeBuilder, which I used to use quite frequently.

You made a good case for curl'ing once:

$ curl -o 1.weather.html 'https://www.wunderground.com/weather/us/or/p +ortland' % 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 $

I find your script quite elegant and readable:

$ ./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' ); $

Q1) What other fields are worth looking at at wunderground?

Q2) Any idea what the KORPORTL966 part of this url signfies?

https://www.wunderground.com/hourly/us/or/portland/KORPORTL966

(This has nothing to do with the parent response.) Q3) Why can't I crack this with Mojo?

#!/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. $

Thanks everybody for presentations on a successful first day. As if covid could keep perl down....

Replies are listed 'Best First'.
Re^3: creating a webpage to fetch/calculate weather data
by marto (Cardinal) on Jun 25, 2020 at 06:21 UTC
Re^3: creating a webpage to fetch/calculate weather data
by marto (Cardinal) on Jun 28, 2020 at 08:48 UTC

    "Why can't I crack this with Mojo?"

    Alternatively just get the URL using Mojo::UserAgent, in exactly the same way as all of the other Mojo based examples you've been provided with.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11118480]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2024-04-19 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found