Having problem using Mechanize to log into Google Account

Discussion in 'Ruby' started by Kevin Lee, Jun 11, 2007.

  1. Kevin Lee

    Kevin Lee Guest

    I am struggling with Mechanize to login to my Google account. Here is
    my code:

    agent = WWW::Mechanize.new
    page = agent.get('https://www.google.com/accounts/ServiceLogin?....')
    # or http://www.google.com/calendar

    google_form = page.forms[0]
    google_form.fields.name("Email").first.value = 'myaddress'
    google_form.fields.find {|f| f.name == 'Passwd'}.value = 'mypasswd'

    pp page
    results = agent.submit(google_form, google_form.buttons.first)
    pp page
    puts results.body

    The values of the Email and Passwd fields remain empty. So it appears
    to me that the code fails to login. What more should I do? Please
    help!

    Thanks in advance!

    --
    Posted via http://www.ruby-forum.com/.
     
    Kevin Lee, Jun 11, 2007
    #1
    1. Advertising

  2. Kevin Lee

    Peter Szinek Guest

    Kevin,

    > The values of the Email and Passwd fields remain empty. So it appears
    > to me that the code fails to login. What more should I do? Please
    > help!


    Mechanize can not handle Javascript, so it won't work this way. You have
    two options here:

    1) Scrape the non-JS page - check this article:

    http://schf.uc.org/articles/2007/02/14/scraping-gmail-with-mechanize-and-hpricot

    2) Use Watir (FireWatir if you are not on win32) which can handle
    JavaScript.

    btw, posting mechanize related questions to the mechanize list
    () can yield better response time/quality.

    HTH,
    Peter
    _
    http://www.rubyrailways.com :: Ruby and Web2.0 blog
    http://scrubyt.org :: Ruby web scraping framework
    http://rubykitchensink.ca/ :: The indexed archive of all things Ruby.
     
    Peter Szinek, Jun 11, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. su z q
    Replies:
    1
    Views:
    251
    Manish Pandit
    Oct 8, 2006
  2. lanclot
    Replies:
    5
    Views:
    309
    David Thompson
    Nov 25, 2007
  3. nilapenn
    Replies:
    3
    Views:
    660
    Joe Kaplan \(MVP - ADSI\)
    Feb 14, 2005
  4. Replies:
    11
    Views:
    258
  5. Rodion Raskolnikov

    How to get redirect log in Mechanize?

    Rodion Raskolnikov, Aug 30, 2009, in forum: Ruby
    Replies:
    0
    Views:
    206
    Rodion Raskolnikov
    Aug 30, 2009
Loading...

Share This Page