Solved

Testing a URL

Posted on 1998-12-02
6
201 Views
Last Modified: 2010-03-04
I have a script in mind that will help me keep track of some of my links on my web page. I know how to do just about everything I am after. Only one problem. I need a little part of the script to test the URL I give it and tell me "GOOD" or "BAD".

For example, I could call a subroutine $good=&Test_URL("http:://www.test.com") and $good would contain 0 if the site responds with a 404 error, and 1 if anything else is returned.

Can you help with this subroutine please?
0
Comment
Question by:schworak
6 Comments
 
LVL 2

Expert Comment

by:irp
ID: 1206699
You could search for the word 404 in a response to a get from port 80 on the target server, however, this page contains a 404, in fact it contains two. How do you propose to distinguish these from real 404's (that's three now).
0
 
LVL 1

Expert Comment

by:adrianwatkins
ID: 1206700
if you were to create a routing I would you a telnet module as a starting point. Take the URL for example www.company.com/test.html split it into host and directory/file.

Now telnet host on port 80 and issue a get directory/file.

Now you will have to parse the response and decide what determines an error. However some 404 pages don't say much about them been a 404 on them - even though to be compliant the must.

Should take ~3/4 hours of playing look for telnet.pm to help with the socket stuff.


0
 
LVL 5

Expert Comment

by:b2pi
ID: 1206701
telnet??? Try perldoc lwpcook

use LWP::Simple;
$doc = get 'http://www.test.com";


will get you the source of what you're trying to find.  

use LWP::Simple;
($content_type, $document_length, $modified_time,  $expires, $server) = head("http://www.test.com");

will help you get around the 404 problem, too.

0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Author Comment

by:schworak
ID: 1206702
The telnet idea would work but is not reliable or predictable.

The LWP idea was the one I was looking for but couldn't find the docs on how to do it. Thanks.

The points will be awarded to b2pi if you just submit a message as an answer. Your answer is 100% what I am after. Thanks!
0
 
LVL 5

Accepted Solution

by:
b2pi earned 200 total points
ID: 1206703
telnet??? Try perldoc lwpcook

       use LWP::Simple;
       $doc = get 'http://www.test.com";


       will get you the source of what you're trying to find.  

       use LWP::Simple;
       ($content_type, $document_length, $modified_time,  $expires, $server) = head("http://www.test.com");

       will help you get around the 404 problem, too.






0
 
LVL 3

Author Comment

by:schworak
ID: 1206704
Thanks! The code works just great!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question