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

    Join Date
    Jul 2004
    Posts
    8
    Rep Power
    0

    Website login program


    Would anyone happen to have a small python program (with or without gui) that can log a user into a website, at regular intervals?

    The program would have to take the following as input

    1. the URL of a website (http)
    2. the user ID
    3. the user pasword
    4. click (simulate a keypress or mouse click) on the button to log the user in.

    if the user could not be logged in, due to the website being overloaded, then it would do a retry at the next interval (where the interval can be supplied by the user, preferably in seconds)

    Or could someone explain how to do this?
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Is the Login page a normal html form? What method is used (GET or POST)?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    8
    Rep Power
    0
    normal html form
  6. #4
  7. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    8
    Rep Power
    0
    Get
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    8
    Rep Power
    0
    if u could show me some source code I'd appreciate it
  12. #7
  13. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Here is a simple script:
    Code:
    import httplib
    import time
    site = "www.mysite.com"
    form = "/cgi-bin/form.py" #the path to the login form processor
    username = "MyName"
    password = "MyPassword"
    form_data = "?USERNAMEFIELD=%s&PASSWORDFIELD=%s"%(username, password) #Change USERNAMEFIELD and PASSWORDFIELD for the form you are using
    wait = 10 #Wait period 10 minutes if site is busy.
    login_ok = "Thank you for logging in" # Some text that would be on the page if login was okay
    
    while True: 
        conn = httplib.HTTPConnection(site)
        conn.request("GET", form+form_data)
        resp = conn.getresponse()
        if resp.status == 404: 
            print "Webpage not found"
            break
        else: 
            data1 = resp.read()
            print data1
            if data1.find(login_ok) != -1: 
                print "Logged in"
                break
            else: 
                print "Trying again in ", wait, "minutes"
                time.sleep(wait*60)
    If you need help with this then please refer to the Python documentation.

    grim
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    8
    Rep Power
    0
    wow, thanks a lot!

IMN logo majestic logo threadwatch logo seochat tools logo