简体   繁体   中英

perl how to find time for http request completion

I have a form to fill and on submit, it will return result. Now, i want to calculate the time taken to fulfill my request ie time when result got displayed-time i clicked submit.

I have no idea, how to do so. Please feel free to use any module. I dont know which parameter to use to check that response page is displayed. I have used reading title of result page just to check that response is displayed correctly.

my code:

use WWW::Mechanize;
use LWP::UserAgent;
my $m = WWW::Mechanize->new();
$m->get( "http://en.wikipedia.org/wiki/Main_Page" );
$m->submit_form(
    form_number => 1,
    fields    => { search  => 'honey', },
    button    => 'go'  #my time1 should start at this moment
);
#my time 2 should be recorded as soon as result page is displayed, i dont know what to use to get this time
$tmp=$m->title;
print "$tmp\n";

您可以使用WWW :: Mechanize :: Timed

You can capture the time when you submit the request and also immediately after result got displayed in the script using time function. Then difference of both can give you the required time taken for the request.

Otherwise you can also try WWW::Mechanize::Timed as Pathak suggested.

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