Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Mojo::DOM exception handling helpby kcott (Archbishop) |
on Aug 01, 2020 at 22:59 UTC ( [id://11120215]=note: print w/replies, xml ) | Need Help?? |
Take a look at the Mojo::DOM documentation; especially the part regarding the at method, whose first sentence is: "Find first descendant element of this element matching the CSS selector and return it as a Mojo::DOM object, or undef if none could be found." Your posted error message reflects what the documentation describes; i.e. $dom1->at('div.abstract-content > p') is returning undef. I can reproduce this:
In order to "catch the exception", you should get the return value from $dom1->at('div.abstract-content > p'). If it is defined, you can use it to invoke the text() method; otherwise, handle as appropriate for your application (output a warning, write to a log, etc.). Based on my code above, you'd want something like this:
Update (additional example): Something of an afterthought and really just intended to show the validity of the previous example:
— Ken
In Section
Seekers of Perl Wisdom
|
|