WWW :: Mechanize :: Firefox超时

时间:2016-01-07 18:16:13

标签: perl firefox mechanize www-mechanize

当我尝试使用->get(URL)发出WWW::Mechanize::Firefox个请求时,如何正确使用超时?

my $mech = WWW::Mechanize::Firefox->new(timeout => 10);似乎不起作用

1 个答案:

答案 0 :(得分:1)

至少在很大程度上可以模拟这一点。

您可以关闭get的同步,在这种情况下,呼叫应立即返回。然后轮询每个$sleep_time直到超时,并对页面是否完成进行一些测试。睡眠允许完成所有其他好页面,因此请根据需要设置$sleep_time

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;
}

存在如何确切确认每个页面的问题,但这应该提供工作超时。