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

Hi Experts,

I am using lwp::useragent to extract the source code from the web page. while extracting the source code, we need to wait/delay for few seconds, as we are using on-load event to load the page.

Is there any option to wait for few seconds to load the page fully before extracting the source code through lwp ? Or any other method to do this ?
  • Comment on Extract the source code after loaded fully

Replies are listed 'Best First'.
Re: Extract the source code after loaded fully
by LanX (Saint) on Jun 21, 2015 at 15:11 UTC
    OnLoad event sounds like JS and LWP can't handle this (even if "delayed" - which doesn't make much sense with HTTP here)

    You'll most likely need a Perl browser automation solution or question your whole concept.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      Yes, i done this page through js with jquery firing. actually i want to know whether the page is fully loaded or not. For this i need to some seconds to load. So is there any way to do this through perl ?
        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Extract the source code after loaded fully
by stevieb (Canon) on Jun 21, 2015 at 15:09 UTC

    Could you post the code snippet you're using, and show where you need to wait? Perhaps sleep() will do what you need, but it's difficult to tell without seeing what's going on.

    -stevieb

      Here is my sample code. i am getting the source code in the $res variable. Initially i am loading the wait message. the page will take some seconds to load. So we need to wait/sleep before extracting the source code
      use lwp::useragent;
      my $ua=lwp::useragent->new();
      my $res= $ua->get(http://mytestpage.com);
      if ($res->is_success){

      }