Posted by Frank Hale on 1999-11-21
> Hi folks,
>
> does anybody have an idea how I might validate a
> given
> external URL within a perl script?
>
> I'm trying to follow the link changes on mp3.com
> with
> a script. It seems as if mp3c just permanently
> renames
> their servers to avoid external downloading. So the
> script
> first has to check different names before it returns
> the
> complete URL to the browser. Any suggestions? Thx!
>
Here is a little snippet of code you can use to open a
URL and get the contents of the page which lives at a
given URL. You can then parse that input for various
errors like 404 or whatever. This probably isn't the
best method but it will work.
use IO::Socket;
my $sock = new IO::Socket::INET (PeerAddr =>
'www.something.com', PeerPort => 'http(80)', Proto =>
'tcp');
die "Couldn't create socket: $@" unless $sock;
$sock->autoflush(1);
$sock->print("GET rest/of/url/here HTTP/1.1\n\n");
my @status=();
push (@status, $sock->getlines());
# Then parse @status and see what you have. Check
# for 404 error or other errors to see if its a valid
# URL. You could also get a copy of the what mp3.com
# uses for its invalid URL page. Then compare the
# contents of @status to that. That may work???
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com
Previous post | Next post | Timeline | Home