Reputation: 1413
I am trying to login into a website through python but the form fields have no name just the ID's
<ul>
<li id="unLi" class="unLi"><input class="text" id="userName" type="text" maxlength="15" /></li>
<li class="blank"></li>
<li id="pwLi" class="pwLi"><input class="text" id="pcPassword" type="password" maxlength="15"/></li>
</ul>
I tried the following code
import requests
params = {'userName':'sahil','pcPassword':'mypassword'}
r = requests.post("http://192.168.1.2/",data=params)
r.status_code
print(r.text)
on submit the form calls a javascript function PCSubWin()
which goes something like this
function PCSubWin()
{
if((httpAutErrorArray[0] == 2) || (httpAutErrorArray[0] == 3))
{
if(true == CheckUserPswInvalid())
{
var username = $("userName").value;
var password = $("pcPassword").value;
if(httpAutErrorArray[1] == 1)
{
password = hex_md5($("pcPassword").value);
}
var auth = "Basic "+ Base64Encoding(username + ":" + password);
document.cookie = "Authorization="+escape(auth)+";path=/";
//location.href ="/userRpm/LoginRpm.htm?Save=Save";
$("loginForm").submit();
return true;
}
else
{
$("note").innerHTML = "NOTE:";
$("tip").innerHTML = "Username and password can contain between 1 - 15 characters and may not include spaces.";
}
}
return false;
now I am not very good at javascript but i assume this peice of code $("userName").value
is getting the values entered by the user, my question is how can I call to this function when submitting my credentials? my code btw prints out the same code for the login page not the user home page.
Upvotes: 0
Views: 219
Reputation: 4394
The site you're requesting is using Basic HTTP Authentication
so you can just call:
requests.get('http://192.168.1.2/userRpm/LoginRpm.htm', auth=('sahil', 'mypassword'))
to access the protected resource.
Upvotes: 1