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

Hi All,
  I'm having a little trouble with LWP. I have a script that grabs pagerank and the HTML for a list of sites. The problem is if it hits a bad site it hangs. I'm trying to limit time it spends on each site so that it doesn't get caught. Here is a code snippet:-

require PageRank; my $PR = WWW::Google::PageRank->new; use LWP::Simple qw($ua get); foreach $siteurl (@websites) { ## Start main loop my $pagerank = $PR->get($siteurl); unless ($pagerank) { $pagerank = 0; } ## End unless $ua->timeout(30); $ua->agent('Blah'); my $html = get($website); } ## End loop

Anyone know what I'm doing wrong, n why it's hanging??

Thanks

Replies are listed 'Best First'.
Re: LWP simple, setting timeout
by Gangabass (Vicar) on Aug 24, 2007 at 00:56 UTC

    Try this one:

    use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Ge +cko/20051111 Firefox/1.5"); $ua->timeout(30);

    LWP::Simple can't change timeout :-(