简体   繁体   English

我可以使用WWW :: Mechanize在Perl中自动执行AngularJS登录表单吗

[英]Can I automate AngularJS login form in Perl using WWW::Mechanize

I have a webpage that uses AngularJS to show a form with a username field, then a password field and the HTML doesn't have any or elements. 我有一个网页 ,该网页使用AngularJS来显示带有用户名字段的表单,然后是密码字段,而HTML没有任何元素。 The next page is a simple HTML form that can be easily automated, two set of fields and a download button. 下一页是一个简单的HTML表单,可以很容易地实现自动化,包括两组字段和一个下载按钮。

I know how to use WWW::Mechanize to automate forms but I'm stuck at the login. 我知道如何使用WWW :: Mechanize自动执行表单,但是我被困在登录名中。 I saw some python ways to do this, but I'm not a pythonist, and prefer Perl. 我看到了一些执行此操作的python方法,但是我不是pythonist,而是更喜欢Perl。

Can WWW:Mechanize do this? WWW:Mechanize可以这样做吗? any other CPAN modules? 还有其他CPAN模块吗?

Here it is. 这里是。 Change login and password and paste what you got. 更改登录名和密码,然后粘贴您得到的内容。 You should get tokenId from API, then use this token to authorization. 您应该从API获取tokenId,然后使用此令牌进行授权。

use LWP::UserAgent;
my $ua = LWP::UserAgent->new();

my $login = 'lucky';
my $password = 'secretpassword';

$ua->default_header('Accept' => 'application/json, text/plain, */*');
$ua->default_header('Content-Type' => 'application/json;charset=UTF-8');
$ua->default_header('Accept-Encoding' => 'gzip, deflate, br');
$ua->default_header('Accept-Language' => 'pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7');
$ua->default_header('Connection' => 'keep-alive');
$ua->default_header('Orgin' => 'https://www.ooredoo.qa');
$ua->default_header('Referer' => 'https://www.ooredoo.qa/selfcare/');
$ua->default_header('Content-Type' => 'application/json;charset=UTF-8');
$ua->default_header('User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36');
my $content = '{"operation":"Login","language":"ENGLISH","parameters":["'.$login.'","'.$password.'"]}';
my $res = $ua->post('https://www.ooredoo.qa/webgate/login', Content => $content );
print $res->decoded_content;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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