in reply to Re^3: Accessing javascript variable from perl
in thread Accessing javascript variable from perl
And the file perl.plvar leg = { aa: "Hello from javascript" } function to_json() { return JSON.stringify(leg); }
I can't have any meaningfull result from calling eval_in_page either on the leg var directly or via the function.use strict; use warnings; use WWW::Mechanize::PhantomJS; my $js = WWW::Mechanize::PhantomJS->new(launch_exe=> 'C:/prog/phantomj +s/bin/phantomjs.exe'); $js->get_local("hello.js"); #$js->update_html('<script src="hello.js" type="text/javascript"></scr +ipt>'); #print $js->content; #my ($val, $type) = $js->eval_in_page('JSON.stringify(window.leg);'); my ($val, $type) = $js->eval_in_page('to_json()'); print "val: $val, type: $type\n";
Can you show me how to have this working ?
Thanks
Update without phantomjsuse strict; use warnings; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($ERROR); use WWW::Mechanize::Chrome; my $js = WWW::Mechanize::Chrome->new(report_js_errors=>1); $js->get_local("hello.js"); #$js->update_html('<script src="hello.js" type="text/javascript"></scr +ipt>'); #print $js->content; #my ($val, $type) = $js->eval_in_page('JSON.stringify(window.leg);'); my ($val, $type) = $js->eval_in_page('to_json()'); print "val: $val, type: $type\n";
This gives undef for $val whatever I'm calling: the to_json() function or JSON.stringify directly.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Accessing javascript variable from perl
by LanX (Saint) on Jun 18, 2019 at 08:15 UTC | |
|
Re^5: Accessing javascript variable from perl
by LanX (Saint) on Jun 18, 2019 at 11:15 UTC | |
by frazap (Monk) on Jun 18, 2019 at 12:12 UTC |