Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Anyway, I found this code from someone else's snippet but oddly enough, when I run it I don't get back any links. Did I forget to copy a line of code or something?
#!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); use LWP::UserAgent; use LWP::Simple qw(!head); use HTML::LinkExtor; use URI::URL; my $url = "http://www.test.com"; my $url = shift; my @links; my $ua = LWP::UserAgent->new; my $p = HTML::LinkExtor->new(\&callback); # Request document and parse it as it arrives my $res = $ua->request(HTTP::Request->new(GET => $url), sub {$p->parse($_[0])}); for ($p->links) { if (defined $_->[2]) { push(@links, $_->[2]); } } foreach my $link (@links) { print "$link<br>"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can't get back links from page
by shmem (Chancellor) on Apr 06, 2007 at 09:38 UTC | |
|
Re: Can't get back links from page
by Samy_rio (Vicar) on Apr 06, 2007 at 04:16 UTC |