Solved

Testing a URL

Posted on 1998-12-02
6
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PERL export multiple query results to a JSON file 1 177
delete query using perl dbi 3 115
rename outfile before writing 2 76
.properties file to call function/method 9 63
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

733 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