#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    7
    Rep Power
    0

    Exclamation automating login form submission


    Hi, I'm trying to write a python script which can log into a website such as stubhub.com . I've been using ClientCookie, ClientForm and urllib2 to do things like submiting search forms, but I haven't been able to get login forms to work. If I use urllib2.urlopen(), the sites ussually give me a nice webpage that says "please try again". If I use ClientCookie.urlopen() to open the login page, submitting the login causes my python script to crash with the following output:
    urllib2.HTTPError: HTTP Error 400: Bad Request

    I have a packet sniffer installed, but I don't know what information I need to look for inside the packets...

    Can someone please help me with code that logs into a site such as stubhub.com?

    Thanks in advance
    -Ben
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    This question is asked very frequently. I am sure a search of the forum will throw up useful examples for you to try A packet sniffer is a bit over the top I think.

    You didn't say what mechanism is used to log in or provide any samples of the failed requests so it is a bit difficult to assist.

    Correction: you did provide a site for us to research

    grimey
    Last edited by Grim Archon; December 21st, 2004 at 11:37 AM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    7
    Rep Power
    0
    I've searched google and in several forums for a solution but I find only PHP scripts for making a website with a login page. I'm trying to write a Python script that will login in to this site:

    https://www.stubhub.com/?gSec=login&cb=www

    The site appears to use https, cookies, sessions, and sends form data via POST. Here's a cleaned up version of the login form:

    <form action="/?gSec=login&cb=www&goto=%2F%3F1%3D1" method="POST" name="loginForm">
    <input type="text" id="nameLogin" name="nameLogin" size="10" class="formFieldText" maxlength="25" tabindex="2" value="" />
    <input type="password" id="password" name="password" size="10" class="formFieldText" maxlength="20" tabindex="3" />
    <input type="checkbox" id="remember" name="remember" value="1" tabindex="4" />
    <input type="submit" class="submitButton" value="Secure Login &gt;" tabindex="5" />
    </form>



    Here's the python script I've been trying to use:

    import ClientCookie
    from ClientForm import ParseResponse

    url = r"https://www.stubhub.com/?gSec=login&cb=www"

    forms = ParseResponse(ClientCookie.urlopen(url))

    form = forms[2]
    print form

    form["password"] = "pass"
    form["nameLogin"] = "my_name"
    req = form.click()


    Running this script causes it to terminate with the following error message:

    urllib2.HTTPError: HTTP Error 400: Bad Request


    I would really appreciate a solution to this problem, or pointers to sources of information..

    Thanks
    -Ben
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    There's actually an example a little further down this forum: http://forums.devshed.com/t209589/s.html

    This was a working example at one point but I haven't tested it since it was written. I've also used this method for logging into a few sites so it is one that works, the hardest part is figuring out what data you need to capture and send onto the next page .

    I haven't used the Client* modules to I'll have to look into it a bit before I'm in a position to give you any help there.

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    7
    Rep Power
    0
    Hi, thanks for the link. I tried the code in

    http://forums.devshed.com/t209589/s.html

    but couldn't get it to work. It seems that code was specifically tailored to login to the devshed site, and I don't know how to change it over so it would work with stubhub.com

    I also downloaded the webunit library(http://webunit.sourceforge.net/), and this seems promising, but it doesn't come with any documentation and I couldn't figure it out just from the short example that comes with it. And even if I could get it to login, I wouldn't know how to navigate the site afterwards using their library.

    Can someone help me get past this?

    Thanks
    -Ben

IMN logo majestic logo threadwatch logo seochat tools logo