0
<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>

I have the above HTML. I want to click the button named full using Mechanize in perl. How can I do this?

I have tried $mech->click("full") and $mech->click_button(name => 'full') and $mech->click_button(value => 'full') but none have worked. They all say there is "no clickable input with name full".

CJ7
  • 22,579
  • 65
  • 193
  • 321

1 Answers1

0

I have no problems downloading your 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);
};

UPDATE

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");

Important note: Parsing HTML with regular expressions is really bad idea (my favorite module is HTML::TreeBuilder::LibXML)

gangabass
  • 10,607
  • 2
  • 23
  • 35
  • OK, try this one: http://daccess-ods.un.org/access.nsf/Get?Open&DS=A/HRC/WGAD/2015/28&Lang=E – CJ7 Mar 12 '16 at 23:10