in reply to Re: LWP hit button to continue
in thread LWP hit button to continue

The link was parsed as seen in the given html: "https://something".
Problem is hitting the button: to agree to continue.

Replies are listed 'Best First'.
Re^3: LWP hit button to continue
by marto (Cardinal) on Mar 23, 2021 at 15:44 UTC

    Quick and dirty example using WWW::Mechanize to get a fake page, click a button, print the title of the next page:

    #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->get('https://derpderpderp.com'); # fake URL $mech->click_button( number => 2 ) # click the second button on fake p +age #do whatever you want with the next page, e.g. print the title print $mech->title;
      Thanks a lot, that's what I am looking for. However now I get an error:
      <h1>Software error:</h1> <pre>Can't call method &quot;click&quot; on an undefined value at C:/P +erl/site/lib/WWW/Mechanize.pm line 982, &lt;STDIN&gt; line 1. </pre> <p> For help, please send mail to this site's webmaster, giving this error + message and the time and date of the error. </p>

      perl:
      use WWW::Mechanize;
      my $ua = WWW::Mechanize->new();
      $ua->get($url); # url page with button
      $ua->click_button( number => 1 ); # there is only one button
      print $ua->title;

        What is the output of:

        perl -MWWW::Mechanize -e 'print $WWW::Mechanize::VERSION ."\n";'

        What is the URL you're hitting.

      Here is a simple example site:

      https://hungergj.home.xs4all.nl/test.htm

      This is the perl program "test button.pl":

      #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $ua = WWW::Mechanize->new(); $ua->get("https:\/\/hungergj.home.xs4all.nl\/test.htm"); $ua->click_button( number => 1 ); print $ua->title; print "=================\n";; $_=<STDIN>;
      The output is this time:
      "click_button: No form has been selected at test button.pl line 12."

        click_button says "Has the effect of clicking a button on the current form by specifying its attributes". The page at that URL doesn't have a form, so you get the expected error message.

        Just use the links instead as previously explained:

        #!/usr/bin/env perl use strict; use warnings; use WWW::Mechanize; my $ua = WWW::Mechanize->new(); $ua->get ('https://hungergj.home.xs4all.nl/test.htm'); my @links = $ua->links(); print $ua->get ($links[0]->url)->decoded_content;

        🦛

      I am afraid giving the link would not be apropriate for this site :-) I thought there was a solution in general terms, so if that is not possible I will leave it at this...

        You didn't answer the other question. If sharing the URL isn't suitable you'll need to do some basic debugging.

      Apologies, I overlooked that.
      Output after having to change ' to "
      1.89SCALAR(0x7db2d4)