Tricking browser into calling javascript events?

橙三吉。 提交于 2019-12-12 06:05:36

问题


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


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/6683611/tricking-browser-into-calling-javascript-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!