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.