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.
In reply to Re^4: Accessing javascript variable from perl
by frazap
in thread Accessing javascript variable from perl
by frazap
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |