Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: WWW::Mechanize submission problem

by monarch (Priest)
on Feb 06, 2006 at 03:55 UTC ( [id://528147]=note: print w/replies, xml ) Need Help??


in reply to WWW::Mechanize submission problem

I use the following function that I wrote to log into yahoo mail and retrieve the number of messages waiting:

sub loginyahoomail( $ $ ) { # arguments my ( $user, $password ) = @_; my $agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'; my $mech = WWW::Mechanize->new( agent => $agent, quiet => 1, onwarn => \&warnfunc, onerror => \&warnfunc, ); $mech->get( "https://mail.yahoo.com/" ); return( undef ) if ( ! $mech->success() ); $debug && print( STDERR "-At->" . $mech->uri() . "\n" ); if ( $mech->response->content =~ m/Yahoo! Mail.*$user/ ) { $mech->follow_link( text => 'Sign Out' ); $debug && print( STDERR "-At->" . $mech->uri() . "\n" ); } return( undef ) if ( ! $mech->success() ); if ( $mech->response->content =~ m/Sign out completely/i ) { $mech->follow_link( text => 'Sign out completely' ); $debug && print( STDERR "-At->" . $mech->uri() . "\n" ); } return( undef ) if ( ! $mech->success() ); my $signinasdiff = 'Sign in as a different user'; if ( $mech->response->content =~ m/$signinasdiff/i ) { $mech->follow_link( text => 'Sign in as a different user' ); $debug && print( STDERR "-At->" . $mech->uri() . "\n" ); } return( undef ) if ( ! $mech->success() ); if ( $mech->response->content =~ m/Return to Yahoo! Mail/ ) { $mech->follow_link( text => 'Return to Yahoo! Mail' ); $debug && print( STDERR "-At->" . $mech->uri() . "\n" ); } return( undef ) if ( ! $mech->success() ); $mech->get( "https://mail.yahoo.com/" ); return( undef ) if ( ! $mech->success() ); if ( $mech->response->content =~ m/login_form/ ) { $mech->form_name( 'login_form' ); $mech->set_fields( login => $user, passwd => $password ); $mech->submit(); } return( undef ) if ( ! $mech->success() ); $debug && print( STDERR "-At->" . $mech->uri() . "\n" ); if ( $mech->response->content =~ m/http-equiv.*refresh.*url=[\'\"]?([^\'\">]+)/i ) { $mech->get( $1 ); $debug && print( STDERR "-At->" . $mech->uri() . "\n" ); } return( undef ) if ( ! $mech->success() ); if ( $mech->response->content =~ m/gWelcomePage\s*=\s*[\"]?([^\r\n\" ]+)/i ) { $mech->get( $1 ); $debug && print( STDERR "-At->" . $mech->uri() . "\n" ); } return( undef ) if ( ! $mech->success() ); if ( $mech->response->content =~ m/You have (?:<b>)?(\d+)\s*unread/i ) { print( STDERR "$1 messages waiting\n" ); } elsif ( $mech->response->content =~ m/>Inbox(\s*\((\d+)\))?</ ) { my $count = $2 || 0; print( STDERR "$count messages waiting\n" ); } # sign out like the good boys we are $mech->follow_link( text => 'Sign Out' ); return( undef ) if ( ! $mech->success() ); if ( $mech->response->content =~ m/(You have successfully closed|You have signed out)/ ) { print( STDERR "Signed out\n" ); } return undef; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-03-28 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found