So i'm trying to create a web spider. I've run into a website, that has some javascript, and I want to trick the browser into thinking that an event has been fired and that it must call the corresponding javascript code to handle the event. How would I be able to do this in Perl? using the WWW::Mechanize or WWW::Scripter::Plugin::Javascript?
Also, it would be very appreciated I someone could put up an example of how to use WWW::Scripter::Plugin::Javascript.
Thanks in advance. Also if someone has a better way to word the question please go ahead and edit it
In a normal browser setup, the JavaScript is in the browser, not on the server. It's the client that executes the JavaScript.
That means you need manually figure out what the JavaScript code does and code that in Perl, or you need to load a JavaScript engine.
Here are three JavaScript engines:
- WWW::Mechanize::Firefox
- Win32::IE::Mechanize
- WWW::Scripter::Plugin::JavaScript
Using WWW::Mechanize
and Live Http Headers, I did a Live Http Replay.
From the replay, I copied the headers (ie Connection: keep-alive to $agent->add_header( "Connection" => "keep-alive");
) and then copied the Post content to my $content = '..
Then $agent->post( $url_of_the_site, Content => $content);
This worked to click a link like 2 on a aspx site.
I used this code as a guide http://pastie.org/1728196/wrap