Used Version of HTML::TreeBuilder::XPath is 0.11

Hi,

i can't figure out why the following script doesn't return anything. The script makes an HTML::TreeBuilder::XPath object from the site http://docstore.mik.ua/orelly/perl4/cook/ch22_07.htm which is fetched via LWP::UserAgent. Then it tries to fetch a node of an absolute XPath and finally fails.

After repeated analysis of http://docstore.mik.ua/orelly/perl4/cook/ch22_07.htm i'm sure that the script has to output 22.6.1. Problem. Instead the script dies at line 18. Maybe someone of you experts can help me to find the error in my reasoning!?

Thanks a lot for your effort and let the wisdom be with you

best regards

s.
#!/usr/bin/perl use strict; use warnings; use HTML::TreeBuilder::XPath; use LWP::UserAgent; my $ua = LWP::UserAgent->new(agent => "Mozilla/5.0"); my $req = HTTP::Request->new(GET => 'http://docstore.mik.ua/orelly/per +l4/cook/ch22_07.htm'); my $res = $ua->request($req); die("error") unless $res->is_success; my $xp = HTML::TreeBuilder::XPath->new_from_content($res->content); my @node = $xp->findnodes_as_strings("/html/body/table[1]/tr/td[2]/di +v/a/h3"); die("node doesn't exist") if $#node == -1; # Line 18 print "$_\n" foreach (@node);

In reply to can't extract node with HTML::TreeBuilder::XPath by saunderson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.