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 |