如何点击按钮(输入类型=隐藏)通过Perl?

时间:2014-11-01 03:19:00

标签: html perl button onclick

我想使用Perl点击按钮。我获取HTML内容,然后找到要单击的按钮。 但是"输入类型=隐藏"当我检查HTML内容时。

  

HTML内容:

<div class="content freepts_cont">

<input type="hidden" id="network" value="5"/>

<div class="like_notification"></div>
  

Firebug内容:

<div class="content freepts_cont">
<input id="network" type="hidden" value="5">
<div class="like_notification"></div>
<div id="site-links-list">
<center>
<div id="L_c3cbf051418f1ec690c445ad843144" class="yt-video-content" style="width: 520px;">
 <div class="likedPagesSingle" style="width:400px;border:1px solid #E8E8E8;padding-top:15px; min-height:250px;">
<center>
<center>
<div class="fb_page_title">
<div style="width:100px; height:100px; overflow:hidden;">
<a style="display:block; width:100px; heigt:100px; overflow:hidden;" href="#">
<img style="width:100%; height:auto;" title="Night Thriller" alt="Night Thriller" src="/images/layout/youtube_page_view.png">
</a>
</div>
<a class="single_like_button btn3-wrap" onclick="openFbLWin(843144, 'JTJGMiUzQSVFMyVEQyUxNSU5MSU4NCUxMSU3RiVFNyU4OCUyM1clM0QyJUM3JUIwMw==');">
</center>
<div class="mtop10" style="margin-bottom:10px;">
<div class="mtop10" style="margin-bottom:10px;">
</div>
</div>

我想用Perl点击:  <a class="single_like_button btn3-wrap" onclick="openFbLWin(843144, 'JTJGMiUzQSVFMyVEQyUxNSU5MSU4NCUxMSU3RiVFNyU4OCUyM1clM0QyJUM3JUIwMw==');">

如何?

1 个答案:

答案 0 :(得分:0)

你最好的选择,根据我自己的经验,很容易设置和使用

WWW::Mechanize

我不完全确定你到底想要做什么 - 更改隐藏输入的值然后提交?也许这个微小且未经测试的片段对你有用。

如果您有更具体的问题,我可能会提供帮助,但CPAN文档到目前为止已经解决了我的任何问题,所以不要过快地解雇它们;)

无论哪种方式,Mechanize都有很好的文档记录,对此任务非常有用。

编辑:我忽略了你给的链接。此代码应该找到它。

Edit2:您可能想尝试WWW::Mechanize::Firefox,它似乎能够处理javascript。我会用它,但我已经习惯了Mechanize。也许其他人可以提出更好的选择。

my $mech = WWW::Mechanize->new();
$mech->follow_link( class => 'single_like_button btn3-wrap' );
# alternatively, get the link object, see what you can do with that
my $link = $mech->find_link( class => 'single_like_button btn3-wrap' );
# or, if it is not the only one of class
my @links = $mech->find_links( class => 'single_like_button btn3-wrap' );
# now somehow get the link out of the list 

这可能不起作用,因为它似乎并未真正提供链接。在这种情况下,尝试使用click()或click_button()。说实话,我将不得不指向那里的文档,因为我对这个特定问题的经验有限,到目前为止,我需要做的就是测试我的网站所需的链接和跟踪。

运气好运!