Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: LWP hit button to continue

by hippo (Bishop)
on Mar 23, 2021 at 15:26 UTC ( [id://11130195]=note: print w/replies, xml ) Need Help??


in reply to LWP hit button to continue

To follow the link you will need to parse it out of the returned content. See the answers to How do I parse links out of a web page for some guidance in that task.


🦛

Replies are listed 'Best First'.
Re^2: LWP hit button to continue
by Anonymous Monk on Mar 23, 2021 at 15:35 UTC
    The link was parsed as seen in the given html: "https://something".
    Problem is hitting the button: to agree to continue.

      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;
        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."
        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;
        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...
        Apologies, I overlooked that.
        Output after having to change ' to "
        1.89SCALAR(0x7db2d4)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11130195]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 16:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found