saunderson has asked for the wisdom of the Perl Monks concerning the following question:
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);
|
|---|