简体   繁体   English

以下链接使用WWW :: Mechanize

[英]Following links using WWW::Mechanize

I am trying to access an internal webpage to start and stop application using WWW::Mechanize. 我正在尝试访问内部网页以使用WWW :: Mechanize启动和停止应用程序。 So far I am able to log in to the application successfully. 到目前为止,我已经能够成功登录该应用程序。 My next action item is to identify a particular service from list of services and stop them. 我的下一个操作项是从服务列表中识别特定服务并停止它们。

The problem I am facing is I am unable to follow the link on the webpage. 我面临的问题是我无法点击网页上的链接。 After looking at the HTML and link object, it is evident that there isn't a URL but an on click event. 查看HTML和链接对象后,很明显没有URL,而是单击事件。

Here is snippet of HTML 这是HTML的代码段

<ul>
<li>
<a href="#" id="j_id_id1:j_id_id9:2:j_id_id10" name="j_id_id1:j_id_id9:2:j_id_id10" onclick="A4J.AJAX.Submit('j_id_id1',event,{'similarityGroupingId':'j_id_id1:j_id_id9:2:j_id_id10','parameters':{'j_id_id1:j_id_id9:2:j_id_id10':'j_id_id1:j_id_id9:2:j_id_id10','ajaxSingle':'j_id_id1:j_id_id9:2:j_id_id10'} ,'containerId':'j_id_id0'} );return false;" style="color:#3BB9FF;">servicename</a>
</li>
</ul>

The link object dump is 链接对象转储为

$VAR1 = \bless( [
                   '#',
                   'servicename',
                   'j_id_id1:j_id_id9:2:j_id_id10',
                   'a',
                   bless( do{\(my $o = 'http://blah.services.jsf')}, 'URI::http' ),
                   {
                     'href' => '#',
                     'style' => 'color:#3BB9FF;',
                     'name' => 'j_id_id1:j_id_id9:2:j_id_id10',
                     'onclick' => 'A4J.AJAX.Submit(\'j_id_id1\',event,{\'similarityGroupingId\':\'j_id_id1:j_id_id9:2:j_id_id10\',\'parameters\':{\'j_id_id1:j_id_id9:2:j_id_id10\':\'j_id_id1:j_id_id9:2:j_id_id10\',\'ajaxSingle\':\'j_id_id1:j_id_id9:2:j_id_id10\'} ,\'containerId\':\'j_id_id0\',\'actionUrl\':\'/pages/services.jsf;jsessionid=NghBSoEJZKXbWcK0uVzcHvyebl8G_zSpf_Zu4uqrLI7xosHAnheK!1108773228\'} );return false;',
                     'id' => 'j_id_id1:j_id_id9:2:j_id_id10'
                   }
                 ], 'WWW::Mechanize::Link' );

Here is my code so far: 到目前为止,这是我的代码:

#!/usr/bin/perl
use strict;
use warnings; 
use Data::Dumper;
use WWW::Mechanize;            

my $username = 'myuser'; 
my $password = 'mypass';
my $url      = 'myinternalurl';

my $mech = WWW::Mechanize->new();
$mech->credentials($username,$password);
$mech->get($url);
my $link = $mech->find_link( text => 'servicename' );
#print Dumper \$link;
#$mech->follow_link( url => $link->url_abs() );
$mech->get($link->url_abs());
print $mech->text();

If I use follow_link , I get Link not found at log_in.pl line 16. . 如果使用follow_link ,则Link not found at log_in.pl line 16. If I use get then I get back the same page. 如果我使用get那么我将返回同一页面。 The problem is all these services appear to be hyperlinks but have the same url as my main url. 问题是所有这些服务似乎都是超链接,但具有与我的主URL相同的URL。

Here is a pic of the webpage: 这是网页的图片:

在此处输入图片说明

When I manually click a service the Operations and Properties section change which allows the user to view Operation and Properties of the service they just clicked. 当我手动单击服务时,“操作和属性”部分会更改,这使用户可以查看他们刚刚单击的服务的“操作和属性”。 Every service has different set of Operations and Properties. 每个服务都有不同的操作和属性集。

How should I go about do this using perl? 我应该如何使用perl做到这一点? Is WWW::Mechanize the wrong tool for this one? WWW ::为此机械化了错误的工具吗? Can anyone please suggest a solution or an alternate perl module that could help. 任何人都可以提出建议的解决方案或替代的Perl模块来提供帮助。 Installing any CPAN module is not an issue. 安装任何CPAN模块都不是问题。 Working with latest version of perl is not an issue either. 使用最新版本的perl也不是问题。 I have just started automating with perl and currently unaware of all the modules that could get the job done. 我刚刚开始使用perl进行自动化,目前还不知道所有可以完成工作的模块。

Looking forward to your guidance and help. 期待您的指导和帮助。

Note: If you feel there is any pertinent information, I may have missed, please leave a comment and I will update the question to add more details. 注意:如果您有任何相关信息,我可能已经错过了,请发表评论,我将更新问题以添加更多详细信息。 I have modified proprietary information. 我已经修改了专有信息。

That button contains a Javascript onclick event, which will not work when using WWW::Mechanize . 该按钮包含一个Javascript onclick事件,在使用WWW::Mechanize时将不起作用。

Per the docs: 根据文档:

Please note that Mech does NOT support JavaScript, you need additional software for that. 请注意,Mech不支持JavaScript,您需要其他软件。 Please check "JavaScript" in WWW::Mechanize::FAQ for more. WWW::Mechanize::FAQ查看“ JavaScript”以获取更多信息。

One alternative that does support Javascript in a forms is WWW::Mechanize::Firefox . WWW::Mechanize::Firefox支持一种形式的Java WWW::Mechanize::Firefox

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

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