Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Help with xpath and TreeBuilder

by Anonymous Monk
on Jun 29, 2012 at 12:09 UTC ( #979111=note: print w/ replies, xml ) Need Help??


in reply to Re: Help with xpath and TreeBuilder
in thread Help with xpath and TreeBuilder

Its even easier :)

my @xpaths = qw{ /html/body/p/a /html/body/p[2]/a /html/body/p[3]/a .... /html/body/p[66]/a }; my $allXpaths = join ' | ', @xpaths; my @values = $tree->findvalues;

I don't know about other xpath interpreters, but treebuilder::xpath (and xsh ) allows this

This query is probably faster

/html/body/p[ position()=1 or position()=2 or position()=3 or position()=66 ]/a

Or this one

/html/body/p[ ( ( position() > 0 and position() < 4 ) or ( position()=66 ) ) ]/a

Though this one won't work with your html  //a[ position()=4] because each //a is at  //a[ position() = 1] because each //a is the only (first) child of its parent ( p ) --- I guess now I know how position() works


Comment on Re^2: Help with xpath and TreeBuilder
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://979111]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (17)
As of 2015-07-30 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls