Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-19 22:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found