Simran wrote:
> Hi All,
>
> Can someone suggest a really simple CPAN module that will validate links
> on a website.
>
> I need something like linklint - except that it needs to be on very very
> simple, and i'm sure there is a CPAN module out there i can use (i just
> can't seem to find a good one)...
>
> All i need to do is:
>
> * Validate the links on pages on a particular site
>
> The reason i don't want to use linklint is that it has some hardcoded
> output formats, and i need to output to a very specific html output
> format, so a perl module that just traversed a site and returned the
> results (rather than save them to a file) would be idea.
HTML::LinkExtor can probably help you here. a simple demo:
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTML::LinkExtor;
#--
#-- i am being very lazy in the demo
#-- you should really localize it in a block
#--
local $/;
my $p = HTML::LinkExtor->new(\&hrefs)->parse(<DATA>);
sub hrefs{
my($tag,@links) = @_;
return unless($tag =~ /^a$/i);
my $p = LWP::UserAgent->new->request(
HTTP::Request->new(GET => $links[1]));
print $p->is_success ? "GOOD: $links[1]" :
$p->status_line . " $links[1]", "\n";
}
__DATA__
<html>
<a href="http://www.ibm.com">
<br>
<a href="http://www.perldoc.com">
<a href="http://www.not-found99.com">
</html>
__END__
prints:
GOOD: http://www.hotmail.com
GOOD: http://www.perldoc.com
500 Can't connect to www.not-found99.com:80 (Bad hostname
'www.not-found99.com') http://www.not-found99.com
i believe the HTML::LinkExtor has a better and more complete example so you
should check it out:
perldoc HTML::LinkExtor
david
--
s,.*,<<,e,y,\n,,d,y,.s,10,,s
.ss.s.s...s.s....ss.....s.ss
s.sssss.sssss...s...s..s....
...s.ss..s.sss..ss.s....ss.s
s.sssss.s.ssss..ss.s....ss.s
..s..sss.sssss.ss.sss..ssss.
..sss....s.s....ss.s....ss.s
,....{4},"|?{*=}_'y!'+0!$&;"
,ge,y,!#:$_(-*[./<[EMAIL PROTECTED],b-t,
.y...,$~=q~=?,;^_#+?{~,,$~=~
y.!-&*-/:[EMAIL PROTECTED] ().;s,;,
);,g,s,s,$~s,g,y,y,%,,g,eval
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>