I’m going to test this on gmail just because it’s a simple platform that a lot of people have and will know how to use. Please enlighten me if a) my code is wrong and b) what are the parameter inputs that are required for the webform.
My code is currently:
data = {'Email':"Emailtypedhere",'Passwd':"Passwordtypedhere"}
#note that I use 'Email' and 'Passwd' based on the name= of the username/password form fields.
#if I should be using it based on the id= please advise. Thanks!
url = "https://accounts.google.com/ServiceLoginAuth"
data_in_string = urllib.parse.urlencode(data)
data_in_bytes = data_in_string.encode('utf-8')
urllib.request.urlopen(url,data_in_bytes)
From that I would assume that I am now logged into gmail. Is that correct? I got the URL from the action type in the form and Passwd from the label form password and the Email from the Email label form.
Here is the code from Gmail, specifically for the form. Please let me know if there are any parameters I am missing or if my code is valid. Thanks!
<form novalidate="" id="gaia_loginform" action="https://accounts.google.com/ServiceLoginAuth" method="post">
<input type="hidden" name="continue" id="continue" value="https://mail.google.com/mail/">
<input type="hidden" name="service" id="service" value="mail">
<input type="hidden" name="rm" id="rm" value="false">
<input type="hidden" name="dsh" id="dsh" value="-6956126811101026847">
<input type="hidden" name="ltmpl" id="ltmpl" value="default">
<input type="hidden" name="hl" id="hl" value="en">
<input type="hidden" name="scc" id="scc" value="1">
<input type="hidden" name="ss" id="ss" value="1">
<input type="hidden" name="GALX" value="q83s3oZvHfE">
<input type="hidden" id="pstMsg" name="pstMsg" value="1">
<input type="hidden" id="dnConn" name="dnConn" value="">
<input type="hidden" id="checkConnection" name="checkConnection" value="youtube:377:1">
<input type="hidden" id="checkedDomains" name="checkedDomains" value="youtube">
<input type="hidden" name="timeStmp" id="timeStmp" value="">
<input type="hidden" name="secTok" id="secTok" value="">
<div class="email-div">
<label for="Email"><strong class="email-label">Username</strong></label>
<input type="email" spellcheck="false" name="Email" id="Email" value="">
</div>
<div class="passwd-div">
<label for="Passwd"><strong class="passwd-label">Password</strong></label>
<input type="password" name="Passwd" id="Passwd">
</div>
<input type="submit" class="g-button g-button-submit" name="signIn" id="signIn" value="Sign in">
<label class="remember" onclick="">
<input type="checkbox" name="PersistentCookie" id="PersistentCookie" value="yes">
<strong class="remember-label">
Stay signed in
</strong>
</label>
<input type="hidden" name="rmShown" value="1">
</form>
You picked an interesting choice to start with 🙂 It sounds like your purpose is solely to figure out which elements you need to submit for a given form (rather than ‘How do I log in to Gmail?’, which would use a completely different process). The short (and admittedly uneducated) answer is that the ‘real’ checks are done on the server side, so there is no requirement for there to be an indication on the client side (although HTML5 seems to provide a way). Therefore you can’t say with certainty which will be required just by looking at the form.
As for your example, I messed around with logging into Gmail in this way a while back, and I remember needing to use the
GALXanddshvalues (two internal Gmail variables) provided in the form. So your arguments would need to be:You would then encode the arguments and open the URL. There is probably a better method of determining the required values, but I recall testing combinations until I was able to access with just those that were required. Again, if you are trying to log in to Gmail then this is not the way, but you made it clear this is just an example, so I guess no warning necessary 🙂