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; }

In reply to Re: WWW::Mechanize submission problem by monarch
in thread WWW::Mechanize submission problem by no21

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.