Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37678

Re: Need Pattern For Logging Into A Website

From Tim Daneliuk <tundra@tundraware.com>
Newsgroups comp.lang.python
Subject Re: Need Pattern For Logging Into A Website
Date 2013-01-25 10:18 -0600
Organization A noiseless patient Spider
Message-ID <qrnat9-lli2.ln1@ozzie.tundraware.com> (permalink)
References <gp39t9-9rk1.ln1@ozzie.tundraware.com> <3f55e471-8657-4cad-96cd-96e9e2e01a9d@googlegroups.com>

Show all headers | View raw


On 01/25/2013 10:01 AM, Steve Petrie wrote:
> On Thursday, January 24, 2013 8:29:51 PM UTC-5, Tim Daneliuk wrote:
>> I need to write a Python script to do the following:
>>
>>
>>
>>     - Connect to a URL and accept any certificate - self-signed or authoritative
>>
>>     - Provide login name/password credentials
>>
>>     - Fill in some presented fields
>>
>>     - Hit a "Submit" button
>>
>>
>>
>> Why?  Because I don't want to have to start a browser and do this
>>
>> interactively every time I authenticate with a particular server.
>>
>> I want to do this at the command line with no interactive intervention.
>>
>>
>>
>> I know Python pretty well.  I don't quite know how to do this and
>>
>> was hoping someone had a simple pattern they could share for
>>
>> doing this.
>>
>>
>>
>> TIA,
>>
>> --
>>
>> ----------------------------------------------------------------------------
>>
>> Tim Daneliuk     tundra@tundraware.com
>>
>> PGP Key:         http://www.tundraware.com/PGP/
>
> The mechanize module (http://wwwsearch.sourceforge.net/mechanize/) might be a place to start.  I've done something similar with code like this:
>
> response = mechanize.urlopen(login_form_url)
> forms = mechanize.ParseResponse(response, backwards_compat=False)
> response.close()
> form = forms[0]                               # might be more than one, though
>                                                # fill the form
> form.set_value(username, name='userName')
> form.set_value(password, name='password')
>                                                # set headers - user-agent, etc.
> login_request = form.click()
> login_response = mechanize.urlopen(login_request)
> login_response_content = login_response.read()
> ...
>

Thanks.

-- 
----------------------------------------------------------------------------
Tim Daneliuk     tundra@tundraware.com
PGP Key:         http://www.tundraware.com/PGP/

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Need Pattern For Logging Into A Website Tim Daneliuk <tundra@tundraware.com> - 2013-01-24 19:29 -0600
  Re: Need Pattern For Logging Into A Website Steve Petrie <spetrie@gmail.com> - 2013-01-25 08:01 -0800
    Re: Need Pattern For Logging Into A Website Tim Daneliuk <tundra@tundraware.com> - 2013-01-25 10:18 -0600
      Re: Need Pattern For Logging Into A Website Michael Torrie <torriem@gmail.com> - 2013-01-25 12:18 -0700
        Re: Need Pattern For Logging Into A Website Tim Daneliuk <tundra@tundraware.com> - 2013-01-25 18:15 -0600
          Re: Need Pattern For Logging Into A Website Michael Torrie <torriem@gmail.com> - 2013-01-25 23:53 -0700
            Re: Need Pattern For Logging Into A Website Tim Daneliuk <tundra@tundraware.com> - 2013-01-26 14:00 -0600
  Re: Need Pattern For Logging Into A Website Jan Wąsak <jhnwsk@gmail.com> - 2013-01-28 00:57 -0800

csiph-web