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">
<div>
<!--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?
For more information visit: https://docs.python.org/2/library/urllib2.html
Let me try to make it simple, suppose URL of the site is www.example.com and you need to sign up by filling username and password, so we go to the login page say http://www.example.com/login.php now and view it's source code and search for the action URL it will be in form tag something like
now take userinfo.php to make absolute URL which will be 'http://example.com/userinfo.php', now run a simple python script
I Hope that this helps someone somewhere someday.
Web page automation ? Definitely "webbot"
webbot
even works web pages which have dynamically changing id and classnames and has more methods and features than selenium or mechanize.The docs are also pretty straight forward and simple to use : https://webbot.readthedocs.io
Typically you'll need cookies to log into a site, which means cookielib, urllib and urllib2. Here's a class which I wrote back when I was playing Facebook web games:
You won't necessarily need the HTTPS or Redirect handlers, but they don't hurt, and it makes the opener much more robust. You also might not need cookies, but it's hard to tell just from the form that you've posted. I suspect that you might, purely from the 'Remember me' input that's been commented out.
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:
You can use
showforms()
to list all forms once you usedgo(...)
to browse to the site you want to login. Just try it from the python interpreter.Websites in general can check authorization in many different ways, but the one you're targeting seems to make it reasonably easy for you.
All you need is to
POST
to theauth/login
URL a form-encoded blob with the various fields you see there (forget the labelsfor
, they're decoration for human visitors).handle=whatever&password-clear=pwd
and so on, as long as you know the values for the handle (AKA email) and password you should be fine.Presumably that POST will redirect you to some "you've successfully logged in" page with a
Set-Cookie
header validating your session (be sure to save that cookie and send it back on further interaction along the session!).