如何模拟“a”上的点击与 Perl WWW::HtmlUnit 链接
我正在使用 Perl 和 WWW::HtmlUnit 库来访问以下站点: https://www.cnatra.navy.mil/scheds/schedule_data .aspx?sq=VT-7
我可以加载该页面,单击“查看时间表”和“搜索”按钮,但无法单击其中的编号日期之一ctrl 日历。
我一直在研究 click() 函数,但在调用此函数之前,我必须将要单击的链接定义为元素。
我有什么想法可以真正让程序找到并单击这些链接吗?
这是来自该网站的代码,描述了我要单击的链接:
<td align="center" style="width:14%;">
<a href="javascript:__doPostBack('ctrlCalendar','4241')"
style="color:Black" title="August 12">12</a>
</td>
这是我将其放入的简化代码:
use WWW::HtmlUnit;
use Inline::Java;
my $webClient = WWW::HtmlUnit->new;
$webClient->setUseInsecureSSL(1);
my $page = $webClient->getPage("https://www.cnatra.navy.mil/scheds
/schedule_data.aspx?sq=vt-7");
###define $daylink element here. This is the calendar link I want to click
my $sched = $daylink->click();
my $content = $sched->asXml;
print "\n$content\n\n";
I'm working with Perl and the WWW::HtmlUnit library to access the following site:
https://www.cnatra.navy.mil/scheds/schedule_data.aspx?sq=VT-7
I can load the page, click on the "view Schedule" and "search" buttons, but I can not click on one of the numbered days in the ctrl calendar.
I have been looking at the click() function, but I must define the link I'd like to click on as an element before this function can be called.
Any ideas how I could actually get the program to find and click these links?
Here's the code from the site describing the link I'd like to click:
<td align="center" style="width:14%;">
<a href="javascript:__doPostBack('ctrlCalendar','4241')"
style="color:Black" title="August 12">12</a>
</td>
Here's the simplified code I will put it in:
use WWW::HtmlUnit;
use Inline::Java;
my $webClient = WWW::HtmlUnit->new;
$webClient->setUseInsecureSSL(1);
my $page = $webClient->getPage("https://www.cnatra.navy.mil/scheds
/schedule_data.aspx?sq=vt-7");
###define $daylink element here. This is the calendar link I want to click
my $sched = $daylink->click();
my $content = $sched->asXml;
print "\n$content\n\n";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于表、TR/TD 和链接都没有 ID/名称,因此您需要通过属性搜索找到适当的元素。幸运的是,HTMLUnit 专门为此提供了一个 API:
getOneHtmlElementByAttribute
。尝试这样的事情(未测试,因为我无权访问)
Since neither the table nor TR/TD nor links have IDs/names, you need to find the appropriate element via attribute search. Luckily, HTMLUnit provides an API just for that:
getOneHtmlElementByAttribute
.Try something like this (not tested as I have no access)