Shady Shady - 1 year ago 82
Python Question

How can I login to a website with Python?

How can I do it?
I was trying to enter some specified link (with urllib), but to do it, I need to log in.

I have this source from the site:

<form id="login-form" action="auth/login" method="post">
<!--label for="rememberme">Remember me</label><input type="checkbox" class="remember" checked="checked" name="remember me" /-->
<label for="email" id="email-label" class="no-js">Email</label>
<input id="email-email" type="text" name="handle" value="" autocomplete="off" />
<label for="combination" id="combo-label" class="no-js">Combination</label>
<input id="password-clear" type="text" value="Combination" autocomplete="off" />
<input id="password-password" type="password" name="password" value="" autocomplete="off" />
<input id="sumbitLogin" class="signin" type="submit" value="Sign In" />

Is this possible?

Answer Source

Maybe you want to use twill (it's based on mechanize). It's quite easy to use and should be able to do what you want.

It will look like the following:

from twill.commands import *

fv("1", "email-email", "")
fv("1", "password-clear", "testpass")


You can use showforms() to list all forms once you used go(...) to browse to the site you want to login. Just try it from the python interpreter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download