Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Sep 2005 19:57:59 -0400
From:      Parv <parv@pair.com>
To:        Charles Maner <ckjmaner@yahoo.com>
Cc:        freebsd-ports@freebsd.org
Subject:   Re: Perl libwww--LWP::Simple
Message-ID:  <20050904235759.GA19238@holestein.holy.cow>
In-Reply-To: <20050904230401.9653.qmail@web54501.mail.yahoo.com>
References:  <20050904213928.GA17782@holestein.holy.cow> <20050904230401.9653.qmail@web54501.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
in message <20050904230401.9653.qmail@web54501.mail.yahoo.com>,
wrote Charles Maner thusly...
>

Could you please not post your reply before the quoted text?


> Hi Parv--thanks for the reply.  My code, on all three
> platforms, is:
> 
> ##### Begin Code ##########
> use strict 'vars';
> use strict 'subs';
> 
> use LWP::Simple;
> 
> LWP::Simple::getstore("http://biz.yahoo.com/i/","tickers.html")
> or die("Website not found!\n");
> 
> open TICKERS, "tickers.html";

You should check the return value of open(), else you will get bogus
error from close() if the file does not exist.


> my @tickers = <TICKERS>;
> 
> print "@tickers\n";
> 
> close TICKERS;
> 
> exit;
> ##### End Code ##########

When i run the above code i get the page intended for a robot; below
are the first few lines ...

  <html><head><title>Yahoo! Finance Company and Fund
  Index</title></head><body><center><!-- Sp
  aceID=0 robot -->
  </center><center><p><!-- SpaceID=0 robot -->
  <table><tr align=center><td><!-- SpaceID=0 robot -->


... working alright.

Given (from LWP::Simple pod) ...

  getstore($url, $file)
    Gets a document identified by a URL and stores it in the file. The
    return value is the HTTP response code.


... you need to check the HTTP return code from getstore() which is
DIFFERENT from perl return values.  Say, if getstore() returns 404,
above code will continue to work past the close() (if tickers.html
already exists) till the exit().

I say, just use the LWP::UserAgent module and get better/easier/more
control.


  - Parv

-- 




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050904235759.GA19238>