Can't figure out why Google won't let me log into my account. I put my email inside a variable called my_mail then search for it in the html but the results came back false.
I am using the requests & beautifulsoup modules to do so.
What I have:
from bs4 import BeautifulSoup
import requests
form_data={'Email': 'ExampleEmail#gmail.com', 'Passwd': 'Password'}
post = "https://accounts.google.com/signin/challenge/sl/password"
my_mail = 'ExampleEmail#gmail.com'
with requests.Session() as s:
soup = BeautifulSoup(s.get("https://accounts.google.com/ServiceLogin?elo=1").text, "html.parser")
for inp in soup.select("#gaia_loginform input[name]"):
if inp["name"] not in form_data:
form_data[inp["name"]] = inp["value"]
s.post(post, form_data)
print(my_mail in "https://mail.google.com/mail/u/0/#inbox")
Form info:
<form novalidate="" method="post" action="https://accounts.google.com/signin/challenge/sl/password" id="gaia_loginform">
<input name="Page" type="hidden" value="PasswordSeparationSignIn">
<input type="hidden" name="GALX" value="c90FYb-yd6E">
<input type="hidden" name="gxf" value="AFoagUVMILWKQvqlGV0i8sJG83jiQlrWzg:1475424777331">
<input id="profile-information" name="ProfileInformation" type="hidden" value="">
<input type="hidden" id="_utf8" name="_utf8" value="☃">
<input type="hidden" name="bgresponse" id="bgresponse" value="js_disabled">
<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:230:1">
<input type="hidden" id="checkedDomains" name="checkedDomains" value="youtube">
<div class="form-panel first valid" id="gaia_firstform">
<div class="slide-out ">
<div class="input-wrapper focused">
<div id="identifier-shown">
<div>
<label class="hidden-label" for="Email">
Enter your email</label>
<input id="Email" type="email" value="" spellcheck="false" name="Email" placeholder="Enter your email" autofocus="">
<input id="Passwd-hidden" type="password" spellcheck="false" class="hidden">
</div>
</div>
<span role="alert" class="error-msg" id="errormsg_0_Email"></span>
</div>
<div style="display: none" id="identifier-captcha">
<input type="hidden" name="identifiertoken" id="identifier-token" value="">
<input type="hidden" name="identifiertoken_audio" id="identifier-token-audio">
<div class="audio-box">
<div id="playIdentifierAudio"></div>
</div>
<div id="captcha-box" class="captcha-box">
<div id="captcha-img" class="captcha-img" data-alt-text="Visual verification">
</div>
<span class="captcha-msg">
Letters are not case-sensitive
</span>
</div>
<label for="identifier-captcha-input" class="hidden-label"></label>
<input type="text" id="identifier-captcha-input" name="identifier-captcha-input" class="captcha" placeholder="Enter the letters above" title="Type the characters you see or numbers you hear">
</div>
<input id="next" name="signIn" class="rc-button rc-button-submit" type="submit" value="Next">
<a class="need-help" href="https://accounts.google.com/signin/usernamerecovery?hl=en">
Find my account
</a>
</div>
</div>
<a href="https://accounts.google.com/ServiceLogin" tabindex="-1">
<img id="back-arrow" class="back-arrow " aria-label="Back" tabindex="0" alt="Back" src="https://www.gstatic.com/images/icons/material/system/1x/arrow_back_grey600_24dp.png">
</a>
<div class="form-panel second">
<div class="slide-in hide-form">
<div>
<p id="profile-name"></p>
<span id="email-display"></span>
</div>
<div>
<div id="password-shown"></div>
</div>
<input id="signIn" name="signIn" class="rc-button rc-button-submit" type="submit" value="Sign in">
<label class="remember">
<input id="PersistentCookie" name="PersistentCookie" type="checkbox" value="yes" checked="checked">
<span>
Stay signed in
</span>
<div class="bubble-wrap" role="tooltip">
<div class="bubble-pointer"></div>
<div class="bubble">
For your convenience, keep this checked. On shared devices, additional precautions are recommended.
Learn more
</div>
</div>
</label>
<input type="hidden" name="rmShown" value="1">
<a id="link-forgot-passwd" class="need-help" href="https://accounts.google.com/signin/recovery?hl=en">
Forgot password?
</a>
</div>
</div>
<span id="inge" style="display: none" role="alert" class="error-msg">
Sorry, Google doesn't recognize that email. Create an account using that address?
</span>
<span id="timeoutError" style="display: none" role="alert" class="error-msg">
Something went wrong. Check your connection and try again.
</span>
</form>
I don't plan on using Google's API. I don't want to be restricted.
Why is the login failing? What could I do to fix it?
I need to login to scrap some information that requires a login.
Pyhton 3.4.2
Related
Basically, this is the element form, ive already identified the forms to fill however, I dont know how to use the specific button to submit:
browser['email']= "abc#gmail.com"
browser['pwd']='password'
These were identified by mechanicalsoup when browser.form.print_summary() was called.
<input autocomplete="off" class="form-control" data-lbl="Email Address" id="login_email" maxlength="255" name="email" placeholder="Enter the email address" type="email"/>
<input aria-describedby="passworderror" autocomplete="off" class="form-control" data-lbl="Password" id="login_pwd" maxlength="25" name="pwd" oncopy="return false" ondrag="return false" ondrop="return false" placeholder="Enter the password" type="password"/>
<button class="btn btn-lg button-orange" type="button">Sign In</button>
<form class="form-horizontal" id="login" role="form" method="POST">
<div class="hidden" id="mandatory-message"> is a mandatory field</div>
<div class="hidden" id="email-message">Please enter a valid email address. For example: johndoe#example.com</div>
<div class="hidden" id="password-message">Please enter 6 or more characters. Leading or trailing spaces will be ignored.</div>
<div class="form-group col-md-12 ">
<label class="control-label " for="login_email">Email Address*</label>
<input type="email" class="form-control valid" id="login_email" name="email" data-lbl="Email Address" placeholder="Enter the email address" autocomplete="off" maxlength="255">
<span id="loginEmailError" class="error"></span>
</div>
<div class="form-group col-md-12">
<label class="control-label" for="login_pwd">Password*</label>
<i id="eye-icon" class="fa fa-fw fa-eye field-icon"></i>
<input type="password" class="form-control valid" id="login_pwd" name="pwd" data-lbl="Password" placeholder="Enter the password" autocomplete="off" maxlength="25" oncopy="return false" ondrag="return false" ondrop="return false" aria-describedby="passworderror">
<span id="passworderror" class="error"></span>
</div>
<div class="form-group col-md-12">
<div class="reloadModal">Forgot your password?</div>
</div>
<div class="login-loading">
<p></p>
<div class="line-pulse"><div></div><div></div><div></div><div></div></div>
</div>
<div class="form-group col-md-12 text-center" id="login_submit">
<button type="button" class="btn btn-lg button-orange">Sign In</button>
</div>
</form>```
I want to fill in a loginForm using BeautifulSoup (I know it's not the easiest way) but I don't know how I can do that. Here under the loginForm.
<form id="loginForm" class="loginContainer" accept-charset="utf-8" action="/wipb2bweb/j_spring_security_check;jsessionid=C647FBABEB8C4ADC3DCCA3C6C875BECC.prod1" method="post"><fieldset>
<legend>Login</legend>
<img src="/wipb2bweb/_ui/themes/carhartt/images/loginTitle.png"
alt="Login" class="title" />
<form>
<div class="formRow">
<label for="User"><img
src="/wipb2bweb/_ui/themes/carhartt/images/loginLabelUser_de.png"
alt="Benutzername" />
</label>
<input id="User" name="j_username" type="text" value=""/></div>
<div class="formRow">
<label for="Password"><img
src="/wipb2bweb/_ui/themes/carhartt/images/loginLabelPass_de.png"
alt="Passwort" />
</label>
<input id="Password" name="j_password" type="password" value=""/></div>
<input type="submit" class="hiddenSubmit"/>
<a href="#" title="Login" class="btnGreyTextured">
<span>Login</span>
</a>
</form>
So I've seen that there are a couple of similar questions but none of them worked for me. This is the login page that I'm trying to log in to:
https://cas.lu.se/cas/login?service=http%3A%2F%2Fwww.ceq.lth.se%2Frapporter%2F%3Flasar_lp%3Dalla%26program%3Dsamtliga%26kurskod%3DEDAA45%26sort%3Dkurskod
The form has the following html:
<div class="box fl-panel" id="login">
<form action="/cas/login;jsessionid=C32FA3678B0093A4DB474BFD56858B6C?service=http%3A%2F%2Fwww.ceq.lth.se%2Frapporter%2F%3Flasar_lp%3Dalla%26program%3Dsamtliga%26kurskod%3DEDAA45%26sort%3Dkurskod" class="fm-v clearfix" id="fm1" method="post">
Please enter your userid without "#lu.se" at the end.<br/><br/>
<div class="row fl-controls-left">
<label class="fl-label" for="username"><span class="accesskey">U</span>sername:</label>
<input accesskey="u" autocomplete="false" class="required" id="username" name="username" onblur="makeLowercase();" size="25" tabindex="1" type="text" value=""/>
</div>
<div class="row fl-controls-left">
<label class="fl-label" for="password"><span class="accesskey">P</span>assword:</label>
<input accesskey="p" autocomplete="off" class="required" id="password" name="password" size="25" tabindex="2" type="password" value=""/>
</div>
<div class="row btn-row">
<input name="lt" type="hidden" value="LT-61720-irxrtm4JCzVNIJ2pkpidljNGOw5KYX"/>
<input name="execution" type="hidden" value="e1s1"/>
<input name="_eventId" type="hidden" value="submit"/>
<input accesskey="l" class="btn-submit" name="submit" tabindex="4" type="submit" value="LOGIN"/>
<input accesskey="c" class="btn-reset" name="reset" tabindex="5" type="reset" value="CLEAR"/>
</div>
</form>
</div>
So far I've tried using urllib in the following way:
from urllib import request, parse
auth = parse.urlencode({"username": "??",
"password": "??",
"lt": "LT-61720-irxrtm4JCzVNIJ2pkpidljNGOw5KYX",
"execution": "e1s1",
"_eventId": "submit",
"submit": "LOGIN", })
auth = auth.encode("ascii")
req = request.Request(url,
with request.urlopen(url) as f:
res = f.read()
The problem is that the only thing I get back is the html for the original page itself, and not the page that it is supposed to load after authentication. I'm also not sure what the action attribute contains in the form tag...
I have written the code below, which is supposed to upload an image to a site called Roblox using Requests.
import requests
s = requests.session()
login_data = dict(username='USERNAMEHERE', password='PASSWORDHERE')
s.post('https://www.roblox.com/newlogin', data=login_data)
upload_data = dict(name="PythonUpload")
r = s.post('http://www.roblox.com/build/upload', files={'file': open('PythonDecalUploadTest.jpg', 'rb')}, data=upload_data)
print(r) #This returns a 500 error
Here is the form that this is posting to.
<form action="/build/upload" enctype="multipart/form-data" id="upload-form" method="post">
<input name="__RequestVerificationToken" type="hidden" value="H_69BCzd4bdyJ7EXalAOvaa-zeZZOvtQR-E9YHnCpmH9HVZKxHGrSVjAciLInCibyD8k432ZRzqX8d0MPPfCv-vOfAM1">
<input id="assetTypeId" name="assetTypeId" type="hidden" value="13">
<input id="isOggUploadEnabled" name="isOggUploadEnabled" type="hidden" value="True">
<input id="groupId" name="groupId" type="hidden" value="">
<input id="onVerificationPage" name="onVerificationPage" type="hidden" value="False">
<div id="container">
<div class="form-row">
<label for="file">Find your image:</label>
<input id="file" type="file" name="file" tabindex="1">
<span id="file-error" class="error"></span>
</div>
<div class="form-row">
<label for="name">Decal Name:</label>
<input id="name" type="text" class="text-box text-box-medium" name="name" maxlength="50" tabindex="2">
<span id="name-error" class="error"></span>
</div>
<div class="form-row submit-buttons">
<a id="upload-button" class="btn-medium btn-primary btn-level-element " tabindex="3">Upload</a>
<span id="loading-container">
<img src="http://images.rbxcdn.com/ec4e85b0c4396cf753a06fade0a8d8af.gif">
</span>
</div>
</div>
</form>
I'm not sure what the request verification token is, so I just changed a few letters/numbers just in case.
So why is this returning a 500 error? Why isn't it uploading my image?
I am trying to write python code which does the following:
1) Logs into OKCupid
2) Goes to a users questions page
3) Answers an unanswered question.
I am using RoboBrowser to do this. I can do steps 1), 2) and I can get the form of the question I want to submit, but once I submit (using RoboBrowser's submit) it doesn't seem to go through to OKCupid (in that the question isn't registered as answered on my profile).
Here is the code I have. Note the My_RoboBrowser just allows me to pass False to RoboBrowser.open for the verify argument.
class My_RoboBrowser(RoboBrowser):
def __init__(self, auth=None, parser=None, headers=None, user_agent=None, history=True):
RoboBrowser.__init__(self, parser=None, user_agent=None, history=True)
def Open(self, vURL, vVerify=True):
response = self.session.get(vURL, verify=vVerify)
self._update_state(response)
browser = My_RoboBrowser()
urlL = 'https://okcupid.com/login'
browser.open(url)
form = browser.get_form(id='loginbox_form')
form['username'] = 'Username'
form['password'] = 'Password'
browser.submit_form(form)
urlQ = 'https://www.okcupid.com/profile/USER/questions?low=1'
browser.open(urlQ)
Question_Tag = browser.find_all(class_="not_answered")[0]
ID = Question_Tag.get('data-qid')
#Get the form to fill out
Form = browser.get_form(id='answer_'+str(ID))
Form['my_answer'].value = '1'
Form['their_answer'].value = ['1']
Form['importance'].value = '1'
browser.submit_form(Form)
Also if it is helpful when I look at the form object Form in an IPython notebook it says:
<RoboForm my_answer=, their_answer=[], importance=>
before the submit and
<RoboForm my_answer=1, their_answer=['1'], importance=1>
after.
Finally, if it is helpful, the following is the code for one of the forms I am trying to answer (which was gotten by inspecting the element)
<form id="answer_179268" name="answer_179268" class="answer_area okform initialized">
<div class="container my_answer">
<input id="my_answer_1_179268" name="my_answer" value="1" false="" type="radio">
<label class="radio" for="my_answer_1_179268">
<span class="icon"></span>
Yes
</label>
<input id="my_answer_2_179268" name="my_answer" value="2" false="" type="radio"></input>
<label class="radio" for="my_answer_2_179268">
<span class="icon"></span>
No
</label>
</div>
<div class="container acceptable_answers">
<div class="title">
<p>Answer(s) you’ll accept</p>
</div>
<label class="checkbox acceptable_answer" for="their_answer_1_179268">
<input id="their_answer_1_179268" class="acceptable_answer" name="their_answer" value="1" false="" type="checkbox"></input>
<span class="icon"></span>
Yes
</label>
<label class="checkbox acceptable_answer" for="their_answer_2_179268">
<input id="their_answer_2_179268" class="acceptable_answer" name="their_answer" value="2" false="" type="checkbox"></input?
<span class="icon"></span>
No
</label>
<label class="checkbox irrelevant" for="their_answer_any_179268">
<input id="their_answer_any_179268" class="irrelevant" name="their_answer" value="irrelevant" type="checkbox"></input>
<span class="icon"></span>
Any of the above
</label>
</div>
<div class="container importance">
<div class="title">
<p>Importance</p>
</div>
<div class="importance_radios">
<input id="importance_179268_5" name="importance" value="5" false="" type="radio"></input>
<label class="importance_5 radio" for="importance_179268_5" data-count="5">
<span class="icon"></span>
<div class="bar"></div>
<span class="label"></span>
</label>
<input id="importance_179268_4" name="importance" value="4" false="" type="radio"></input>
<label class="importance_4 radio" for="importance_179268_4" data-count="4">
<span class="icon"></span>
<div class="bar"></div>
<span class="label">A little</span>
</label>
<input id="importance_179268_3" name="importance" value="3" false="" type="radio"></input>
<label class="importance_3 radio" for="importance_179268_3" data-count="3">
<span class="icon"></span>
<div class="bar"></div>
<span class="label">Somewhat</span>
</label>
<input id="importance_179268_2" name="importance" value="2" false="" type="radio"> </input>
<label class="importance_2 radio" for="importance_179268_2" data-count="2">
<span class="icon"></span>
<div class="bar"></div>
<span class="label"></span>
</label>
<input id="importance_179268_1" name="importance" value="1" false="" type="radio"> </input>
<label class="importance_1 radio" for="importance_179268_1" data-count="1">
<span class="icon"></span>
<div class="bar"></div>
<span class="label">Very</span>
</label>
</div>
<div class="irrelevant_message">
<span class="irrelevant_text">Irrelevant</span>
<span class="message_text">(Because you’ll accept any answer, this question is marked irrelevant)</span>
</div>
</div>
<div id="explanation_container_179268" class="container explanation">
<div id="answer_179268_explanationContainer" class="inputcontainer textarea noresize empty">
<textarea id="answer_179268_explanation" class="noresize" placeholder="Explain your answer (optional)" false=""></textarea>
<span class="message empty" style="height: 0"></span>
<div class="icon"></div>
</div>
</div>
<button id="submit_btn_179268" class="submit_btn flatbutton disabled small">Answer</button>
<button id="cancel_btn_179268" class="cancel_btn flatbutton silver small">Cancel</button>
<a class="skip_btn inner" href="javascript:void(0)" draggable="false">Skip question</a>
<div id="public_container_179268" class="answer_privately">
<label class="checkbox" for="private_179268">
<input id="private_179268" false="" type="checkbox"></input>
<span class="icon"></span>
<span class="text">Answer privately</span>
</label>
</div>
</form>
I've seen several cases where someone couldn't submit b/c the site used Javascript to submit forms. In other words, they could use Robobrowser or Mechanize to log in and fill out a form, but the form itself could not be submitted -- as submission relied on JS. That may be your problem here. If that's the case, you should try using Selenium.
You can likely verify whether JS is being used to submit in your browser's inspector. <ctrl + shift + i / network / *clear* inspector's network panel before clicking submit / click submit / check type for your Post>
I think that's how I verified, but others here would know better than me. Good luck!
You should take a look at https://github.com/IvanMalison/okcupyd. It will let you do this without using a browser.