in reply to how to open page and follow link

Yes, WWW::Mechanize does exactly that, unless clicking the button involves JavaScript. If JavaScript was involved and you're on a Windows machine, I'd use Win32::IE::Mechanize.

As for your second question, it would use the IP address of the machine on which the script is running. I presume you intend to do this from a CGI script. CGI scripts run on the web server, so it'll be the web server's IP address that will be used.

Replies are listed 'Best First'.
Re^2: how to open page and follow link
by Anonymous Monk on Apr 11, 2005 at 03:12 UTC
    Hi. Thanks for your help.

    I am running this code

    #!/usr/bin/perl use warnings; use strict; my $url = "(removed)"; use CGI::Carp qw(fatalsToBrowser); use CGI qw/:standard/; use lib "/home/name/public_html/lib/"; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->get( $url ); print header, start_html(); print $mech->links;
    And is printing out
    WWW::Mechanize::Link=ARRAY(0xa430d5c)WWW::Mechanize::Link=ARRAY(0xa442 +a70)WWW::Mechanize::Link=ARRAY(0xa448fe4)WWW::Mechanize::Link=ARRAY(0 +xa448f00)WWW::Mechanize::Link=ARRAY(0xa444f24)WWW::Mechanize::Link=AR +RAY(0xa4445e0)WWW::Mechanize::Link=ARRAY(0xa442c5c)WWW::Mechanize::Li +nk=ARRAY(0xa4446c4)WWW::Mechanize::Link=ARRAY(0xa444f00)WWW::Mechaniz +e::Link=ARRAY(0xa44c7a0)WWW::Mechanize::Link=ARRAY(0xa448fa8)WWW::Mec +hanize::Link=ARRAY(0xa4450c8)WWW::Mechanize::Link=ARRAY(0xa444670)WWW +::Mechanize::Link=ARRAY(0xa449f44)WWW::Mechanize::Link=ARRAY(0xa44478 +4)WWW::Mechanize::Link=ARRAY(0xa44d31c)WWW::Mechanize::Link=ARRAY(0xa +449efc)WWW::Mechanize::Link=ARRAY(0xa44a004)WWW::Mechanize::Link=ARRA +Y(0xa44e664)WWW::Mechanize::Link=ARRAY(0xa4490f8)WWW::Mechanize::Link +=ARRAY(0xa449f80)WWW::Mechanize::Link=ARRAY(0xa44d664)WWW::Mechanize: +:Link=ARRAY(0xa449c5c)WWW::Mechanize::Link=ARRAY(0xa449ef0)WWW::Mecha +nize::Link=ARRAY(0xa44e6e8)WWW::Mechanize::Link=ARRAY(0xa451b98)WWW:: +Mechanize::Link=ARRAY(0xa44d574)WWW::Mechanize::Link=ARRAY(0xa449d1c) +WWW::Mechanize::Link=ARRAY(0xa4491a0)WWW::Mechanize::Link=ARRAY(0xa45 +2c70)
    Did I do something wrong?

    Thanks.

      links returns an array of objects of type WWW::Mechanize::Link, not an array of strings. Perhaps you want:

      print $_->url(), "\n" foreach $mech->links();
        Yes, that did work. Thanks.

        I tried my own version of (see below) and to my suprise, it didn't work! lol.

        foreach ($mech->links()) { print "$_<br>"}
        But that's okay since yours does. Only reason I wanted to do this was to see what # my link was but from the print out, I don't think the printout order is the order I need in order to follow a specific link.

        Before I try

        $mech->get( $url ); $mech->follow_link( url_regex => qr/Frogs and Toads/i );
        I need to know I'm doing this on the right URL. Is there a way I can check this link? I tried using find_link and printing it out but it's printing out "index.cgi" and NOT the Frogs and Toads link so I have a feeling if I use follow_link it won't be going to the right link.

        How can I be sure?

        Thanks and sorry for the noobie questions

      Perhaps it'd be nice if WWW::Mechanize::Link had '""' overloaded to return the URL, when stringified. It would produce more "intuitive" results for normal use.

      You can currently produce that result by adding this to your code:

      use WWW::Mechanize; BEGIN { package WWW::Mechanize::Link; use overload '""' => \&url_abs; }

      OTOH it wouldn't do much good in your case, as you're trying to generate a HTML page of links. A simple, plain text, list of links then isn't much good.