Shady Shady - 4 months ago 43
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?


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.