<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')
但没有一个工作。他们都说“没有名称完整的可点击输入”。
最佳答案
我下载您的 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)
关于html - 如何在perl中使用Mechanize单击按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35882648/