Ωmega
Ωmega

Reputation: 43673

look_down that checks (inside HTML) content

With HTML::TreeBuilder, using command $root->look_down(_tag => 'a') I get first anchor.

(1) How can I find last anchor?

Additionally, how can I check for inside content of the tag, to check if it does or does not contain some string inside of it? So for example,

(2) how can I find an anchor that contains "Hallo" or "hallo" in inside HTML?

(3) how can I find an anchor that DOES NOT contain "Hallo" or "hallo" in inside HTML?

Upvotes: 1

Views: 237

Answers (1)

Birei
Birei

Reputation: 36272

The look_down() function returns a list of all <a> tags found, so simply access to last element of it using an index, like:

my $last_a_tag = ($root->look_down(_tag => 'a'))[-1]

To search into its text, use content_list() function, that returns a list with all child text elements. Then use a map() function to check if it contains or not any text, like:

map { m/[Hh]allo/ } $last_a_tag->content_list;

Upvotes: 2

Related Questions