简体   繁体   中英

WWW::Mechanize::Firefox Timeout

How do I properly use a timeout when I attempt to make ->get(URL) requests with WWW::Mechanize::Firefox ?

my $mech = WWW::Mechanize::Firefox->new(timeout => 10); does not seem to work

It is possible to simulate this, at least to a good extent.

You can turn off synchronization for get , in which case the call should return immediately. Then poll every $sleep_time until timeout, with some test of whether the page completed. The sleep allows all those other good pages to complete, so set $sleep_time as appropriate.

my $timeout = 10; 
my $sleep_time = 1;

my $page = get($url, synchronize => 0); 

for (1..$timeout) {
    # Test some page property that will confirm that it loaded
    last if $page->title eq $expected_title;
    sleep $sleep_time;
}

There is the issue of how exactly to confirm each page, but this should provide a working timeout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM