Looking for Mechanize code for login

Hi

I am trying to automate collecting balances from my bank using Mechanize.
I have set

#!/usr/bin/env ruby

require 'rubygems'
require 'mechanize'
require 'pp'

username = "*****"
password = "****"

site_url = "https://online.compassweb.com/servlet/compass/login.jsp"
agent = WWW::Mechanize.new
page = agent.get(site_url)
form = page.forms.first
form.fields.name("UserName").value = username
form.fields.name("Password").value = password
page = agent.submit(form, form.buttons.first)

The page I get back has the following in it:

<script language="JavaScript" type="text/javascript">
     function setLocation(){
             location.replace("/servlet/compass/inc/init/login-init.jsp");
         }
     window.onload=setLocation;
</SCRIPT>
</body>
</html>

Can someone tell me what the process is for retrieving pages like this are?

Thanks

Jim Freeze

Jim Freeze wrote:

Hi

I am trying to automate collecting balances from my bank using Mechanize.
I have set

#!/usr/bin/env ruby

require 'rubygems'
require 'mechanize'
require 'pp'

username = "*****"
password = "****"

site_url = "https://online.compassweb.com/servlet/compass/login.jsp&quot;
agent = WWW::Mechanize.new
page = agent.get(site_url)
form = page.forms.first
form.fields.name("UserName").value = username
form.fields.name("Password").value = password
page = agent.submit(form, form.buttons.first)

The page I get back has the following in it:

<script language="JavaScript" type="text/javascript">
    function setLocation(){
            location.replace("/servlet/compass/inc/init/login-init.jsp");
        }
    window.onload=setLocation;
</SCRIPT>
</body>
</html>

Can someone tell me what the process is for retrieving pages like this are?

If that's all you ever get back, I'd say to first do the login to get the cookies, check that you get what you're expecting back, then just directly agent.get that url.

···

--
Alex

There's a much easier way ... buy Quicken :). Or reverse-engineer
Gnucash, if it works with your bank. :slight_smile:

Alex Young wrote:

···

Jim Freeze wrote:

Hi

I am trying to automate collecting balances from my bank using
Mechanize.
I have set

#!/usr/bin/env ruby

require 'rubygems'
require 'mechanize'
require 'pp'

username = "*****"
password = "****"

site_url = "https://online.compassweb.com/servlet/compass/login.jsp&quot;
agent = WWW::Mechanize.new
page = agent.get(site_url)
form = page.forms.first
form.fields.name("UserName").value = username
form.fields.name("Password").value = password
page = agent.submit(form, form.buttons.first)

The page I get back has the following in it:

<script language="JavaScript" type="text/javascript">
    function setLocation(){
           
location.replace("/servlet/compass/inc/init/login-init.jsp");
        }
    window.onload=setLocation;
</SCRIPT>
</body>
</html>

Can someone tell me what the process is for retrieving pages like
this are?

If that's all you ever get back, I'd say to first do the login to get
the cookies, check that you get what you're expecting back, then just
directly agent.get that url.

--
M. Edward (Ed) Borasky

http://linuxcapacityplanning.com