Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

how to import hotmail addressbook by WWW::Mechanize or something else

by fayland (Acolyte)
on Nov 21, 2006 at 09:07 UTC ( #585221=perlquestion: print w/replies, xml ) Need Help??
fayland has asked for the wisdom of the Perl Monks concerning the following question:

hi, folks.
I have a task that ask me to import the addressbook from Hotmail/MSN/Live.
recently Hotmail is upgraded to its new login.live.com and it seems using a lot of Javascript in its login interface. see http://www.hotmail.com/
and I tried to use WWW::Mechanize:
#!/usr/bin/perl -w use strict; use Data::Dumper; use WWW::Mechanize; my $mech = WWW::Mechanize->new( agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', cookie_jar => {}, stack_depth => 1, autocheck => 1, ); $mech->get('http://www.hotmail.com'); $mech->submit_form( form_name => 'f1', fields => { login => 'myemail@hotmail.com', passwd => 'passwd', LoginOptions => 3, } ); print $mech->content();
It keeps telling me that my email and password is incorrect. but I can login by my browser indeed.
I would wonder if someone is in the same situation and offer me a help. Thanks a lot.
PS, WWW::Hotmail is too much outdated.
  • Comment on how to import hotmail addressbook by WWW::Mechanize or something else
  • Download Code

Replies are listed 'Best First'.
Re: how to import hotmail addressbook by WWW::Mechanize or something else
by inman (Curate) on Nov 21, 2006 at 13:48 UTC
    The login process looks complicated but it is ultimately cookie based and will just take some working out. You can avoid getting the script to log in by preparing the cookies beforehand.

    Try logging into hotmail using Mozilla or Firefox as your browser (I prefer Mozilla for this). Clear the cookies using the cookie manager. Choose the "save my credentials" option when you log in. This saves a number of cookies into the cookies.txt file. (location varies depending on OS but try under C:\Documents and Settings\<MyAccount>\Application Data\Mozilla\Profiles on Windows).

    The cookies.txt file is in Netscape Format so you will need to load it up using HTTP::Cookies::Netscape. All your code needs to do now is to handle the redirection (which WWW::Mechanize should do OK).

    This is all untested but I have used a similar script elsewhere. In general, Mozilla and LiveHTTPHeaders is a good debug combination.

      yup, I tried as what you said. no luck indeed.
      use HTTP::Cookies::Netscape; my $cookie_jar = HTTP::Cookies::Netscape->new( file => 'E:/lwp_cookies.dat', autosave => 1, ); my $mech = WWW::Mechanize->new( agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', cookie_jar => $cookie_jar, stack_depth => 1, autocheck => 1, );
      mm, we brought a script written by php. it uses 'curl_exec' and works fine. I tried to search in CPAN. and find WWW::Curl, but failed to install this module. (install progress stoped at test).
      I just wonder whether anyone has written a similar script and give me a hint.
      Thanks for your tip any way, inman.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://585221]
Approved by lidden
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2018-11-13 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (146 votes). Check out past polls.

    Notices?