ophielia has asked for the wisdom of the Perl Monks concerning the following question:

I'm working with libwww for the first time. I am trying to parse the content on a html page on a intranet server to find a certain error code. Basically, what I'm using is this: $fileToCheck = 'http://internalservername/'; use LWP::UserAgent; $ua = new LWP::UserAgent; $ua->agent("MyFirstAgent /" . $ua->agent); $req = new HTTP::Request HEAD => $fileToCheck; $res = $ua->request($req); if ($res->is_success) { print "file $fileToCheck exists\n"; print $res->content; } else { print "file $fileToCheck doesn't exist\n"; } $res->content is always nothing. That's my problem. When I break there, and 'X res', here's what my feedback looks like: '_content' => '' '_headers' => HTTP::Headers=HASH(0x11297c4) 'accept-ranges' => 'bytes' 'client-date' => 'Fri, 15 Sep 2000 10:58:34 GMT' 'client-peer' => '10.0.0.4:80' 'content-length' => 1775 'content-location' => 'http://internalservername/Default.htm' 'content-type' => 'text/html' 'date' => 'Fri, 15 Sep 2000 11:01:05 GMT' 'etag' => '"0a4e2ee8cc7bb1:20ee"' 'last-modified' => 'Fri, 01 Nov 1996 00:38:00 GMT' 'server' => 'Microsoft-IIS/4.0' '_msg' => 'OK' '_protocol' => 'HTTP/1.1' '_rc' => 200 '_request' => HTTP::Request=HASH(0x1126338) '_content' => '' '_headers' => HTTP::Headers=HASH(0x1126308) 'user-agent' => 'MyFirstAgent /libwww-perl/5.45' '_method' => 'HEAD' '_uri' => URI::URL=ARRAY(0x11263d4) 0 URI::http=SCALAR(0x10f8628) -> 'http://internalservername/' 1 undef Is libwww such that an http://internalservername won't work? Does it have to be a IP Address or a www.*.com address? Am I barking up the wrong tree with libwww and should be using Sockets instead? Any help would be appreciated! margaret no spiffy quotes.
  • Comment on retrieving html content from intranet server

Replies are listed 'Best First'.
Re: retrieving html content from intranet server
by kilinrax (Deacon) on Sep 15, 2000 at 15:33 UTC
    Please wrap your code in <code> tags, otherwise it comes out as an unintelligible mess.

    I think what your trying to do is similar to the below:
    #!/usr/bin/perl -w eval 'exec perl -w -S $0 ${1+"$@"}' if 0; # not running under some shell require 5; use strict; use LWP::UserAgent; use URI::URL; my $ua = new LWP::UserAgent; $ua->agent("ExciteMespGrabber/1.0 " . $ua->agent); $ua->env_proxy; my $uri; $uri = new URI::URL "http://www.excite.co.uk/"; my $req = new HTTP::Request GET => $uri->as_string; my $res = $ua->request($req); if (!$res->is_success) { die "Fetch failed\n"; } my $content = $res->content; if ($content =~ /<!--\s+ExciteMesp{(\S+)}\s+-->/) { print "Check ok for: $1\n"; } elsif ( $content ) { print "MESP ok, but contains no monitoring comment\n"; } else { print "Check failed!\n"; }
    Feel free to tell me if you find this helpful.... or if i was completely off the mark ;-)
Re: retrieving html content from intranet server
by Anonymous Monk on Sep 15, 2000 at 16:21 UTC
    No, I found this very helpful - the <code> tip as well. My problem, I think, was twofold... First, I had left out the proxy. Secondly, once I had included it, the HTTP_proxy variable on my computer was set incorrectly. :-( Now I can do what I need to do. Thanks for your help!