简体   繁体   中英

How submit that form through perl for Openwrt/LEDE

I have that form

<form method="post" action="index.lp" name="authform" id="authform">
<input type="password" name="password" id="password" onkeypress="return enter_submit(event);" />
<input name="enter" class="btn btn-primary" type="button" value="log in" onclick='auth()' />

I can submit it thanks javascript in that way

javascript:document.getElementById("password").value = "password";auth();

Now i need to write perl script to do it automatically and when it log in execute an other javascript function in page. I'm testing it on computer and have some problem:

1) Perl need ac compiler...after i can install it on openwrt?

2) I can try 2 different ways:

The first and more rapid is to use WWW::Scripter::Plugin::JavaScript but i cannot install the module because i cannot install mingw (i did, in ppm-shell, install mingw and it return "ppm install failed: Can't find any package that provides mingw"). Furthermore i don't see WWW::Scripter in Perl package . I wrote that script (can it work?):

  use WWW::Scripter;
  $w = new WWW::Scripter;

  $w->use_plugin('JavaScript');
  $w->get('http://url');
  $w->get('javascript:document.getElementById("password").value = "password";auth();');
  sleep (1);
  $w->get('http://url');
  $w->get('javascript: function();');

The second is to use WWW:Mechanize. How i can see output page? And how i can send command to the second page? Now with that script i get this error: "Missing base argument at D:/Program Files/Perl/lib/HTTP/Response.pm line 92.". (can it work?)

use WWW::Mechanize;
my $mech = WWW::Mechanize->new();

$mech->get( $url );

$mech->follow_link( url => 'http://url' );

$mech->submit_form(
    form_name => 'authform',
    fields    => { password  => 'password', },
    button    => 'log in'
);

I'd work with WWW::Mechanize, interpreting JS that relies on the DOM without a real browser engine is close to impossible.

$mech->content() will get you the raw HTML from WWW::Mechanize's last fetched page.

If you do have JavaScript-heavy pages that you need to automate and you want to use perl, look into using Selenium's WebDriver to control a "real" browser (even if it's headless like phantomjs).

As for the Error you are getting: make sure that your steps work correctly, and look at what's happening in D:/Program Files/Perl/lib/HTTP/Response.pm line 92, and what it does expect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM