Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: searching with mojo dom

by adambot (Acolyte)
on Mar 11, 2018 at 23:56 UTC ( [id://1210695]=note: print w/replies, xml ) Need Help??


in reply to Re: searching with mojo dom
in thread searching with mojo dom

Here is my final code that works. If anyone has a better way to do it, please share.

my $dom = Mojo::DOM->new($source); my $sidecarsource = $dom->find('div.today_nowcard-sidecar')->first(qr/ +Right Now/)->content; #print Data::Dumper::Dumper($sidecarsource); my $sidecardom = Mojo::DOM->new($sidecarsource); my $wind = $sidecardom->at('table > tbody > tr:nth-child(1) > td > spa +n')->text;

Replies are listed 'Best First'.
Re^3: searching with mojo dom
by marto (Cardinal) on Mar 12, 2018 at 09:49 UTC

    You might find this cleaner:

    #!/usr/bin/perl use strict; use warnings; use feature 'say'; use Mojo::UserAgent; my $url = 'https://weather.com/weather/today/l/20001:4:US'; my $selector = 'div.today_nowcard-sidecar.component.panel table tr td +span'; my $ua = Mojo::UserAgent->new; say $ua->get( $url )->res->dom->at( $selector )->all_text;

    However, you may want to check if their recommended API, if it offers what you want it'll be faster to access and your code more resilient to changes.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-16 12:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found