Need help with Mojo::Dom and collections #1928
-
Hi everyone, I'm trying to parse a webpage using Mojo::Dom and a ua. My ultimate goal is to mail part of it's content, but so far I'm wondering how I can use it's functions to populate a hashref for instance (not show in the code below). I managed to print out text using print or say, but if I try to map it to an array in a hashref, using ->each or ->join("\n") or even map->(text) it simply fails. When printing with Data::Dumper it shows a Mojo::Collection object and I can't seem to understand how to access it.
Here's some code ` use local::lib '/home/luc/perl5/lib/perl5'; my $url = 'https://www.aa.org/fr/daily-reflections'; my $main = $dom->at('div.reflection');
} print $title, $strong; ` Thanks in advance for your help |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
In the best case you can address a tag that surrounds the text you want to read and extract it in one step. As with my $dom = $ua->get('https://mojolicious.org')->res->dom;
say $dom->at('.mojo-fortune')->all_text; |
Beta Was this translation helpful? Give feedback.
In the best case you can address a tag that surrounds the text you want to read and extract it in one step. As with