perloc perloc - 6 months ago 34
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?

Thanks..

Answer

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

Synopsis:

#!/usr/bin/perl

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

$w = new WWW::Scripter;
$w->use_plugin('JavaScript');  # packaged separately
$w->get('http://some.site.com/that/relies/on/javascript');
$w->eval(' alert("Hello from JavaScript") ');
$w->document->getElementsByTagName('div')->[0]->....
$w->content; # returns the HTML content, possibly modified by scripts