<input type="hidden" name="hiddenConsolidateFiles" value="0">
<button type="button" style="width:220px;" onClick="javascript:viewFullTextOfTreaty()" value="full" name="full" id="full">View Full Text of Treaty</button>
<button type="button" style="display:none;" onClick="javascript:viewFullText()" value="" id="sim">View Other Relevant Treaty Information</button>
<button type="button" style="display:none;" onClick="javascript:viewConsolidated()" value="consol" name="consol" id="consol">View Consolidated Version of Treaty</button>
我有以上HTML
。我想在full
中使用Mechanize
点击名为perl
的按钮。我怎样才能做到这一点?
我尝试了$mech->click("full")
和$mech->click_button(name => 'full')
以及$mech->click_button(value => 'full')
,但都没有效果。他们都说“没有名字已满的可点击输入”。
答案 0 :(得分:0)
下载PDF时没问题:
my $url =
"http://ec.europa.eu/world/agreements/downloadFile.do?fullText=yes&treatyTransId=520";
{
my $mech = WWW::Mechanize->new();
$mech->get($url);
my ($filename) = $mech->{res}->{_headers}->{"content-disposition"} =~ m{filename=([^"]+)};
$mech->save_content($filename);
};
<强>更新强>
my $url =
"http://daccess-ods.un.org/access.nsf/Get?Open&DS=A/HRC/WGAD/2015/28&Lang=E";
my $mech = WWW::Mechanize->new();
$mech->get($url);
$mech->save_content("1.htm");
#HTTP-EQUIV="refresh" URL
my ($tmp_url) = $mech->content() =~ m{URL=([^"]+)};
$mech->get( "http://daccess-ods.un.org" . $tmp_url );
$mech->save_content("2.htm");
my ($pdf_url) = $mech->content() =~ m{URL=([^"]+)};
my ($cookie_url) = $mech->content() =~ m{src\s*=\s*"([^"]+)};
#First we need to get cookies
$mech->get($cookie_url);
#Next we can load PDF file
$mech->get($pdf_url);
$mech->save_content("Result.pdf");
重要提示: 用正则表达式解析HTML真是个坏主意(我最喜欢的模块是HTML :: TreeBuilder :: LibXML)