Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to release or kill Mechanize session

Thread Tools

How to release or kill Mechanize session

Posts: n/a
I am using scripts like the following to retrieve web data.
After login I use another instance of $mech->get($url) to
get data from links on the retrieved page.
Sometimes I get a login failure which may be due to the page
timing out. Rather than have this happen I decided to deliberately
end each session after a few downloads then do the login again.
If I enclose my script with the statements perl.begin; and perl.end;
this seems to have worked.

My question: Is this the correct way to kill or release a Mechanize session?
Any comments or suggestions welcome...cheers, Peter

#!/user/bin/perl -w
use strict;
use warnings;

use WWW::Mechanize;
use DBI;
use HTTP::Cookies;
use Win32::ODBC;

# Do the login...
my ($url,$username,$password);
$url = '';
$username = "xxxx";
$password = "xxxx";
my $mech = WWW::Mechanize->new(
agent => 'Mozilla/4.0',
cookie_jar => {} );
unless ($mech->success)
die "Can't get the login page $url: ",
$mech->field(p_login => $username);
$mech->field(p_password => $password);

my $url1 = '';

unless ($mech->success)
die "Can't get the login page url1 $url1: ",

print "Now retrieving: "$url1,"\n";

# The retrieved page may have up to 10 links
# create an array of the links
my @links = $mech->links;
# loop through the links
foreach my $link (@links)
my $href = $link->url;
# Retrieve the link text
my $name = $link->text;
print "href: " , $href, "\n" , "name: " , $name , "\n" ;
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
A way to kill Session user(only one session), solutions... Fabrice ASP .Net 2 09-06-2005 07:53 PM
KILL BABY KILL widescreen drsd2kill DVD Video 3 11-29-2004 09:36 PM
Bava's KILL BABY KILL widescreen drsd2kill DVD Video 0 11-27-2004 12:04 AM
Kill Bill DVD release - 2 parts? Mr. Mike DVD Video 9 10-16-2003 07:47 PM