Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Some issues with WWW::Mechanize::Firefox->xpath() method (xpath 1.0)

by choroba (Cardinal)
on Apr 02, 2013 at 10:22 UTC ( [id://1026649]=note: print w/replies, xml ) Need Help??


in reply to Re: Some issues with WWW::Mechanize::Firefox->xpath() method (xpath 1.0)
in thread Some issues with WWW::Mechanize::Firefox->xpath() method

Works for me (using XML::XSH2):
$ xsh $scratch/> insert element p into /scratch $scratch/> insert text 'Hello world' into /scratch/p $scratch/> echo substring(//p,1,4) Hell
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
  • Comment on Re^2: Some issues with WWW::Mechanize::Firefox->xpath() method (xpath 1.0)
  • Download Code

Replies are listed 'Best First'.
Re^3: Some issues with WWW::Mechanize::Firefox->xpath() method (xpath 1.0)
by Anonymous Monk on Apr 02, 2013 at 10:42 UTC

    Works for me (using XML::XSH2):

    And you're sure that's not an xsh2 function/feature?

    Produces no output for me

    #!/usr/bin/perl -- use strict; use warnings; use XML::LibXML; my $html = <<'__HTML__'; <html> <head> <title>Hello Firefox!</title> </head> <body> <h1>Hello <b>World</b>!</h1> <p id='paragraph'>Hello <b>WWW::Mechanize::Firefox</b> Goob bye</p> </body> </html> __HTML__ my $dom = XML::LibXML->new( qw/ recover 2 / )->load_html( #~ string => \$html, ## BUG! scalar... not like load_xml string => $html, ); local $\ = $/; print for $dom->findnodes(q{ substring(//p,1,4) }); ## nada print for $dom->findnodes(q{ //p }); ## paragraph
      You are using findnodes, but there is no node corresponding to the substring. Use find instead:
      print for $dom->find(q{ substring(//p,1,4) });
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        For reference, WWW::Mechanize::Firefox uses document.evaluate() to execute an XPath query. I don't know how it relates to ->findNodes and ->find, but the return value will always be DOM nodes.

        Javascript in MozRepl::RemoteObject:

        ... var xres = doc.evaluate(q,ref,null,XPathResult.ORDERED_NODE_SNAPSHOT_T +YPE, null ); ...

        You are using findnodes, but there is no node corresponding to the substring. Use find instead:

        Well that certainly works :) but the explanation doesn't make sense to me -- what is a text literal if not a text node?

        This whole time I've been thinking the two functions were interchangeable, if findnodes can't deal with this, it should reject the xpath, not do nothing, but yeah, I'm confused

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-23 17:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found