Get current URL with WWW :: Mechanize PERL


Can you help me get the current URL where I am located (after login)?

use strict;
use WWW::Mechanize;
use HTTP::Cookies;

my $urlActual;
my $url = "xxxxxxxxxxxxxx";
my $palabra;
my $username = 'xxxxxxxxxx';
my $password = 'xxxxxxxxxxxxx';

my $mech = WWW::Mechanize->new();
$mech->field(txt_login => $username);
$mech->field(txt_clave => $password);
my $app_content = $mech->content();

$urlActual = top.frame.location.href

I miss an error in the penultimate line.

Edited: And after receiving some answers about using $mech->uri() , I find the error:

asked by Javier 18.01.2017 в 12:48

3 answers


As it comes in your documentation:




Returns the current URI as a URI object.

Reference to the documentation

answered by 18.01.2017 в 13:05

The error message indicates that you are missing a semicolon ( ; ) on line 18.

Solution: $mech->uri(); (add semicolon)

answered by 18.01.2017 в 17:15

The last two lines do not follow the Perl syntax. They look more like JavaScript.

You must use the uri () method.

answered by 25.01.2017 в 13:46