Hello, I'm submitting each date from 1896 to the present to a form and collecting data on the returned pages. My loop inputs the date value, submits the form, scrapes the page, writes the data to file, goes back one page and sleeps for .1 seconds.

The problem is, I always get disconnected from the server eventually. Sometimes it's after 6 months, and sometimes 4 years. I think this may be a problem with the internet configuration here in my school apartment (I made it through 50 years at home last week), though I don't know how to check/remedy that.

How can I modify the block below to restart the loop at the current iteration whenever disconnection occurs?

Thanks!

use WWW::Mechanize; use Fortran::Format; my $mech = WWW::Mechanize->new(); $mech->get($url); foreach my $date (@dates) { $mech->form_number(1); $mech->field('dtg',"$date"); $mech->click(); my $page = $mech->content(format=>'text'); my @data = ($page =~ /:\s\s\s\s(\d\d)/g); my @rain = ($page =~ /Rain or Liquid Equivalent\s+:\s+(\S*)/); my @snow = ($page =~ /Snow and\/or Ice Pellets\s+:\s+(\S*)/); my @depth = ($page =~ /Snow Depth\s+:\s+(\S*)/); my @hdd = ($page =~ /Degree-Days\s+:\s+(\S*)/); my $f = Fortran::Format->new("(I2.1,2X)")->write($hdd[0]); @hlahdd = ("$date $data[0] $data[1] $data[2] $f"); print "@hlahdd"; print FH "@hlahdd"; sleep .1; $mech->back(); }

In reply to WWW::Mechanize agent timing-out from server by cheech

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.