Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: How do I get WWW::Mechanize::PhantomJS to wait until the JavaScript on the web page has finished executing?

by Corion (Patriarch)
on Aug 21, 2021 at 07:39 UTC ( [id://11136000]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How do I get WWW::Mechanize::PhantomJS to wait until the JavaScript on the web page has finished executing?
in thread How do I get WWW::Mechanize::PhantomJS to wait until the JavaScript on the web page has finished executing?

Maybe just use sleep to wait for three seconds?

  • Comment on Re^3: How do I get WWW::Mechanize::PhantomJS to wait until the JavaScript on the web page has finished executing?

Replies are listed 'Best First'.
Re^4: How do I get WWW::Mechanize::PhantomJS to wait until the JavaScript on the web page has finished executing?
by Darth Ed (Beadle) on Aug 21, 2021 at 17:16 UTC
    Maybe just use sleep to wait for three seconds?
    Sleep between the call to the get method and the call to the decoded_content method? I tried that. No change to the content.

    Is there a different arrangement of methods you recommend? Do you have an example that does something like this?

      > Sleep between the call to the get method and the call to the decoded_content method? I tried that. No change to the content.

      I can't find any decoded_content method documented in WWW::Mechanize::PhantomJS (?)

      Maybe try $mech->content( %options ) ?

      Otherwise are you sure your JS-App really works inside PhantomJS? It wouldn't be the first case of browser incompatibilities.

      update

      The HTTP::Response object returned by WWW::Mechanize has a decoded_content method, I don't know how and if subclassing was done here, but I wouldn't expect that to work with JS.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        I can't find any decoded_content method documented in WWW::Mechanize::PhantomJS (?)
        You're right. It's a WWW::Mechanize method, so I just presumed it worked with WWW::Mechanize::PhantomJS as well. I'll give content a try. Thanks!

        UPDATE: No difference. Same exact result as the decoded_content method.

        Otherwise are you sure your JS-App really works inside PhantomJS? It wouldn't be the first case of browser incompatibilities.
        Yeah, I don't know. That's a good point. Maybe not?

        UPDATE #2: OK, so I think that's the problem. I added print $_->{message},"\n" for $mech->js_errors(); to my code, and I'm getting a mess of TypeError: undefined is not a function (evaluating ...) JavaScript errors that I don't see in any major web browser.

        How very disappointing. I guess I'll have to try to get WWW::Mechanize::Firefox working...

        Or maybe I can inject some polyfills? Seems others have encountered this sort of problem with PhantomJS:
        https://github.com/tom-james-watson/phantomjs-polyfill
        https://github.com/mathiasbynens/String.prototype.startsWith

        I might try that first... I'm thinking the best way to do that is to copy ghostdriver/src/main.js and add the polyfills to that?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11136000]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-25 22:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found