Check a web page exists

Here is a short method to check if a web page exists from a perl script,
this script will test the existense of a page and do something as a result:

use LWP::Simple;
print “Content-Type: text/html\n\n”;

$url = ““;

if (head($url)) {
# ok document exists
print “OK: found $url”;
} else {
# something is not well
print “PROBLEM: $url is missing”;

This script is using the libwww-perl package.

Technorati Tags: , ,

5 thoughts on “Check a web page exists”

  1. I would probably extend it to check the returned error code as well.
    For getting a response doesn’t necessarily mean that all is well. It can be a redirect command or possibly some other type of error. Would you also like to follow a chain of redirects? (you should detect and avert cyclic redirects).
    One more question I’d be curious to know is whether LWP supports HTTPS protocol as well?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>