perloc perloc - 2 years ago 96
Javascript Question

How can I run a Javascript of a web page in Perl?

Possible Duplicate:

How can I use Perl to grab text from a web page that is dynamically generated with JavaScript?

I am interested in learning Perl and just started to write a web crawler in Perl. On the page that I crawled, there is a Javascript for giving vote to the page. It shows the vote of the current page, only if I click the voting stars. So during the crawling, I need to run the Javascript and learn the current voting of the page.

Do you have any suggestions or examples?


Answer Source

You would need to use module WWW::Scripter with WWW::Scripter::Plugin::JavaScript.



use strict;
use warnings;
use WWW::Scripter;

$w = new WWW::Scripter;
$w->use_plugin('JavaScript');  # packaged separately
$w->eval(' alert("Hello from JavaScript") ');
$w->content; # returns the HTML content, possibly modified by scripts
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download