HTH

Yes, it did: adding an alert("hello from js"); in the js file show me that a (the only ?) way to have it executed, was to load an existing html file. Using $js->modify_html('<script src="hello.js" type="text/javascript"></script>')on a blank page did not run the js file.

So, I have to load this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +"> <title>test</title> <script src="hello.js"></script> </head> <body> </body
Then, the following worked:
my $js = WWW::Mechanize::PhantomJS->new(launch_exe=> 'C:/prog/phantomj +s/bin/phantomjs.exe'); #or #my $js = WWW::Mechanize::Chrome->new(report_js_errors=>1); $js->get_local("hello.html"); my ($val, $type) = $js->eval_in_page('JSON.stringify(window.leg);'); #or #my ($val, $type) = $js->eval_in_page('JSON.stringify(leg);'); #or #my ($val, $type) = $js->eval_in_page('to_json()'); print "val: ", Dumper($val), "type: $type\n";

Thanks

frazap


In reply to Re^6: Accessing javascript variable from perl by frazap
in thread Accessing javascript variable from perl by frazap

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.