I know that the title of the question is not so descriptive, but let me explain here.
I am trying to parse a given html document using HTML :: TreeBuilder. Now in this html document the values 5,1,ABC,DEF should be checked for compliance with the value provided by the user, and if this check is successful, I need to extract the href link.
So my code is:
my @tag = $tree->look_down( _tag => 'tr', class => qr{\bepeven\scompleted\b} ); for (@tag) { query_element($_); } sub query_element { my @td_tag = $_[0]->look_down( _tag => 'td' ); my $num1 = shift @td_tag;
Now my approach first extracts the value from td tags and compares it with the value specified by the user, if it is successful, than searching for another value specified by the user ABC or DEF , in my case it is ABC , if it is matched , than only .
Now the containsig tag ABC or DEF has no fixed position, but they will be lower than the tags containing 5 and 1 value. So, I used $_[0]->as_text eq 'ABC'; to verify that the tag contains ABC now in my tree. I am now in text node ABC from here, how can I extract the href i, e link, how can I navigate through the tree of objects and retrieve the value.
PS: I would try xpath here, but the position of the html elements is not so clearly defined and structured.
EDIT:
So, I tried $_->tag() and returned td , but if I am on a td tag, than to why the following code does not work:
my $link_obj = $_->look_down(_tag => 'a')
But this leads to the following error:
Can't call method "as_text" on an undefined value.