I am getting this issue while loggin in to a ajax website, the issue is while login in it requires username, password and checkbox i agree with terms and conditions. I have tried login in with only username and password but it returns an error that you must agree with terms and conditions Can any one help me with this?
from bs4 import BeautifulSoup as bs
import requests
import csv
import urllib.request
URL = 'https://www.somesite.com/Login'
LOGIN_ROUTE = 'https://www.somesite.com/Login/Check'
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.3'
HEADERS={'User-Agent':user_agent}
s = requests.session()
csrf_token = s.get(LOGIN_ROUTE).cookies['__RequestVerificationToken']
print("\ncsrf_token " +csrf_token)
login_payload = {
'Login.UserName': 'username',
'Login.Password': 'password',
'__RequestVerificationToken': csrf_token
}
login_req = s.post(LOGIN_ROUTE, headers=HEADERS, data=login_payload)
if login_req.status_code==200:
print(str(login_req.status_code) + " login successful\n") #if successful, 200 will be returned
else:
print(str(login_req.status_code) + " login unsuccessful")
cookies = login_req.cookies
soup = bs(login_req.text, 'html.parser')
print("Parse text begins here")
print(soup)
the returned page is :
<form
action="/Login/Login"
class="form-signin loginForm"
data-ajax="true"
data-ajax-begin="AjaxBegin()"
data-ajax-complete="AjaxComplete()"
data-ajax-method="POST"
data-ajax-success="Login(data)"
id="mainLoginForm" method="post"
role="form"
>
<input
name="__RequestVerificationToken"
type="hidden"
value="h3aO76bDCl0QOh7HOjH8XWKcyBPfbTR3E6KkF6jf3hL7gJPUbaLlP60gqrVYAxV6wHagvTQK_Azd1GWp50f08s59rnD87TIn2-zX55atrvY1"
/>
<div class="col-sm-12 center_align_tablet">
<input
autofocus=""
class="form-control"
data-val="true"
data-val-required="The Username field is required."
id="username"
name="Login.UserName"
placeholder="User Name"
required=""
style=""
type="text"
value=""
/>
<span
class="field-validation-valid"
data-valmsg-for="Login.UserName"
data-valmsg-replace="true"
style="color:red"
>
</span>
<input
class="form-control"
data-val="true"
data-val-required="The Password field is required."
id="loginPass"
name="Login.Password"
placeholder="Password"
required=""
style="margin-top:10px;"
type="password"
/>
<span
class="field-validation-valid"
data-valmsg-for="Login.Password"
data-valmsg-replace="true"
style="color:red"
>
</span>
<span id="LoginErrorMessage"></span>
<p style="font-size:12px; margin-top:10px;"></p>
<div class="checkbox">
<label>
<input class="agreeBox" type="checkbox" value=""/>
I Agree with the
<a
class="hyperlink"
data-target="#terms_conditions_modal"
data-toggle="modal"
href=""
id="termsPopUp"
>
Terms and Conditions
</a>
of Acceptable Use
</label>
<div class="red" style="color:red;display:none">
Please Agree With Terms & Conditions
</div>
</div>
<button class="btn btn-success btn-block login_btn_tablet" type="submit">Sign in</button>
</div>
</form> </div>
from Python Issue while login in to ajax website with a checkbox of terms and conditions
No comments:
Post a Comment