[ILUG] Quick perl question
Niall O Broin
niall at magicgoeshere.com
Mon Nov 29 16:04:26 GMT 2004
On 29 Nov 2004, at 14:59, Kevin Philp wrote:
> Can't call method "get_trimmed_text" on unblessed reference
>
> my $browser = LWP::UserAgent->new;
> my $url = "http://www.cybercolloids.net/index.php";
> my $response = $browser->get($url);
> die "Error at $url\n ", $response->status_line, "\n Aborting" unless
> $response->is_success;
>
> my $stream = HTML::TokeParser->new(\$response->content) || die "Cannot
> open:
> $!";
>
> while (my $token = $stream->get_tag("a")) {
> my $link = $token->[1]{href} || "-"; # ===OK
> my $text = $token->get_trimmed_text("/a") || "-"; #===Not
> OK
> print "$link\t\n";
> }
$token doesn't have a get_trimmed_text method. $token is whatever is
returned by the get_tag method of $stream. What is $token (in perl
terms) ? get_trimmed_text is a method of HTML::TokeParser so perhaps
the line
> my $text = $token->get_trimmed_text("/a") || "-";
should actually be
my $text = $stream->get_trimmed_text("/a") || "-";
Niall
More information about the ILUG
mailing list