Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Can You Explain How to Check a Link for Deadness

by DigitalKitty (Parson)
on May 12, 2002 at 20:19 UTC ( #166024=note: print w/replies, xml ) Need Help??


in reply to Can You Explain How to Check a Link for Deadness

I don't need something that checks many links, just one.

Hi.

One 'quick and dirty' solution is to use the LWP::Simple module and check the return value of the url that was entered.

#!/usr/bin/perl -w use strict; use LWP::Simple; my $url; my $site; print "URL to check: "; chomp($url = <STDIN>); $site = get($url); if($site) { print "$url is good.\n"; } else { print "$url appears to be broken.\n"; } Sample run with output: C:\perl>perl linkcheck.pl URL to check: http://www.perlmonks.org http://www.perlmonks.org is good. C:\perl>perl linkcheck.pl URL to check: http://www.google.com http://www.google.com is good. C:\perl>perl linkcheck.pl URL to check: http://www.blahblahblah.com http://www.blahblahblah.com appears to be broken. C:\perl>


Hope this helps,

-DigitalKitty

Replies are listed 'Best First'.
Re: Re: Can You Explain How to Check a Link for Deadness
by giulienk (Curate) on May 12, 2002 at 20:41 UTC
    Substituting the call to the get function in the LWP::Simple for a call to head you could save a good amount of time as the head function checks only for the presence of the page instead of downloading it all.


    $|=$_="1g2i1u1l2i4e2n0k",map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://166024]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2021-01-26 00:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?