Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why following XPath statement returns all "a" elements?

Tags:

perl

xpath

print $tree->findvalue('//a[1]');

I am using HTML::TreeBuilder::XPath in perl. Now i expect the above statment to return the value of second "a" element but instead it returns the value of all "a" elements in the page. I cant understand Why?

like image 642
Shubham Avatar asked Feb 13 '26 12:02

Shubham


1 Answers

what you have shall return first a-child of every element.
so //a[1] will work as follows (result will be 2 nodes):

X
 Y
  a <-- give you this
  a
Z
 a <-- and this
 a

try (//a)[1] instead

like image 127
THX-1138 Avatar answered Feb 16 '26 02:02

THX-1138



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!