Posts: 14
Threads: 6
Joined: Feb 2019
Trying to login using requests but I'm getting html returned that appears to be an error page.
Python:
import requests
with requests.Session() as c:
url = "http://10.10.....html"
user_name = input("Enter your username: ")
password = input("Enter your password: ")
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36'}
c.get(url, headers = headers)
login_data = dict(txt_inptUserId = user_name, txt_password = password, headers = headers)
c.post(url, data = login_data)
page = c.get(url)
print(page.content) HTML-Error?:
Quote:C:\Users\user\Desktop\requests>test.py
Enter your username number: xyz
Enter your password: xyz
b'<html>\r\n <head>\r\n <title>App</title>\r\n </head>\r\n <frameset na
me="jacadaframeset" frameborder="0" framespacing="0" rows="100%,*">\r\n <fram
e name="jacadaframe" frameborder="0" marginheight="0" marginwidth="0" src="/Xhtm
l?JacadaApplicationName=App"/>\r\n </frameset>\r\n <noframes>\r\n <p>You
r browser doesn\'t support frames!<p>\r\n window.location.href="/Xhtml?Jacada
ApplicationName=App";\r\n </noframes>\r\n</html>\r\n'
Posts: 7,324
Threads: 123
Joined: Sep 2016
They problem is likely in your log in method,then the return is correct.
It's not possible to help without seeing the page,there is a lot of different method log-in method that web-pages use.
You have to inspect web-page to see what's happens when log in,eg use Chrome/FireFox developer tool.
Have posted this before,example how to log in into this forum see that i need to find params used.
I use Session() so it's persist against requests and cookies.
import requests
from bs4 import BeautifulSoup
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}
params = {
"username": "your_username",
"password": "xxxxxxx",
"remember": "yes",
"submit": "Login",
"action": "do_login",
}
with requests.Session() as s:
s.post('https://python-forum.io/member.php?action=login', headers=headers, params=params)
# logged in! session cookies saved for future requests
response = s.get('https://python-forum.io/index.php')
# cookies sent automatically!
soup = BeautifulSoup(response.content, 'lxml')
welcome = soup.find('span', class_="welcome").text
print(welcome) Output: Welcome back, snippsat. You last visited: Today, 05:44 PM Log Out
Posts: 14
Threads: 6
Joined: Feb 2019
May-07-2019, 05:21 PM
(This post was last modified: May-07-2019, 07:09 PM by snippsat.)
Here's a rundown of the tags/elements:
<input id="inptUserId" maxlength="8"
name="txt_inptUserId" onkeyup="autoSkipNN(event.which,this);" onfocus="saveFocusedControl("inptUserId");" style="background-color:Window;font-size:11px;height:19px;width:67px;line-height:11px;left:275px;padding-bottom:0;font-family:Arial;border-width:2px;position:absolute;border-style:inset;top:101px;color:000000;padding-top:0;" tabindex="26"
title="" type="text" value=""> <input id="password" maxlength="8"
name="txt_password" onkeyup="autoSkipNN(event.which,this);" onfocus="saveFocusedControl("password");" style="background-color:Window;font-size:11px;height:19px;width:67px;line-height:11px;left:445px;padding-bottom:0;font-family:Arial;border-width:2px;position:absolute;border-style:inset;top:101px;color:000000;padding-top:0;" tabindex="28"
title="" type="password" value=""> Then I need to click this button after logging in:
<input alt="Enter" id="btnOK"
name="btn_btnOK" onfocus="saveFocusedControl("btnOK");" style="font-family: Arial; font-size: 12px; font-weight: Bold; position: absolute; left: 19px; top: 292px; width: 49px; height: 23px; color: #ffffcc; background-color: transparent; border-width: 0px; text-align:left;padding-left:0px;padding-right: -5px;cursor: pointer; padding-left:0px;padding-right:0px;" tabindex="-1"
title="" type="submit" value="Enter"> (May-07-2019, 04:34 PM)snippsat Wrote: I use Session() so it's persist against requests and cookies. What is Session()? Is that a function/method of requests or another module itself? Thanks.
Also, does this help?
Form Data
Output: Applname: App
Formname: SIGNON
sessionId: 180...
sequenceNumber: 2
focusedControl: NewPassword
keepAliveURL: /KeepAlive?
keepAliveInterval: 60000
clientDebugLevel: 0
defaultbtn_btnOK: activate default
default_btnOK: 1
txt_txtActiveHelpHtml:
txt_txtPrevFocus:
txt_txtRecordFlag:
txt_txtMacros:
txt_txtFieldValue:
txt_txtMugShots:
txt_txtSavedHelpValue:
txt_txtFavorites:
txt_txtTableLinkStyle: -1
txt_txtKeyBoardSupport:
txt_inptUserId: myUserName
txt_password: abc123
txt_NewPassword:
Posts: 7,324
Threads: 123
Joined: Sep 2016
May-08-2019, 08:48 AM
(This post was last modified: May-08-2019, 08:48 AM by snippsat.)
I fixed code tags in your post,look at BBCode
rudolphyaber Wrote:What is Session()? Is that a function/method of requests or another module itself? Thanks. Session Objects when you use a browser the states eg cookies is kept.
Doing it outside of browser need to keep state persist,when eg doing request(get, post).
You are using Session in your post so that's okay.
rudolphyaber Wrote:Also, does this help?
Form Data Is this form data of html on site?
You have to look in Network tab of Chrome/FireFox developer tool,when you try to log in browser.
Then Form Data that get send can be found.
Posts: 14
Threads: 6
Joined: Feb 2019
(May-08-2019, 08:48 AM)snippsat Wrote: Is this form data of html on site?
You have to look in Network tab of Chrome/FireFox developer tool,when you try to log in browser.
Then Form Data that get send can be found.
Yes it got this from under the Network tab of Chrome's developer tools.
Posts: 7,324
Threads: 123
Joined: Sep 2016
May-11-2019, 08:36 AM
(This post was last modified: May-11-2019, 08:36 AM by snippsat.)
Not sure without looking is all of that is send as form data.
Can try this, if fail try to send all that you posted.
params = {
txt_txtActiveHelpHtml: '',
txt_txtPrevFocus: '',
txt_txtRecordFlag: '',
txt_txtMacros: '',
txt_txtFieldValue: '',
txt_txtMugShots: '',
txt_txtSavedHelpValue: '',
txt_txtFavorites: '',
txt_txtTableLinkStyle: -1,
txt_txtKeyBoardSupport: '',
txt_inptUserId: myUserName ,
txt_password: abc123 ,
txt_NewPassword: '',
}
Posts: 14
Threads: 6
Joined: Feb 2019
May-14-2019, 07:19 PM
(This post was last modified: May-14-2019, 07:19 PM by rudolphyaber.)
(May-11-2019, 08:36 AM)snippsat Wrote: Not sure without looking is all of that is send as form data.
Can try this, if fail try to send all that you posted. All that the user enters into the form in the browser is the username and password. I also have two screenshots but the image button on here only lets me use a url, I don't see a way to upload the images.
I added this code:
params = { txt_txtActiveHelpHtml: '',
txt_txtPrevFocus: '',
txt_txtRecordFlag: '',
txt_txtMacros: '',
txt_txtFieldValue: '',
txt_txtMugShots: '',
txt_txtSavedHelpValue: '',
txt_txtFavorites: '',
txt_txtTableLinkStyle: -1,
txt_txtKeyBoardSupport: '',
txt_inptUserId: {user_name},
txt_password: {password},
txt_NewPassword: '', and this is what I got:
params = { txt_txtActiveHelpHtml: '',
NameError: name 'txt_txtActiveHelpHtml' is not defined
It actually give this error for all of them. But these are the variable that chrome shows for form data for logging in.
Posts: 7,324
Threads: 123
Joined: Sep 2016
All should be string,so like this.
params = {
"txt_txtActiveHelpHtml": '',
"txt_txtPrevFocus": '',
"txt_txtRecordFlag": '',
"txt_txtMacros": '',
"txt_txtFieldValue": '',
"txt_txtMugShots": '',
"txt_txtSavedHelpValue": '',
"txt_txtFavorites": '',
"txt_txtTableLinkStyle": -1,
"txt_txtKeyBoardSupport": '',
"txt_inptUserId": 'myUserName',
"txt_password": 'abc123',
"txt_NewPassword": '',
}
Posts: 14
Threads: 6
Joined: Feb 2019
May-15-2019, 03:34 PM
(This post was last modified: May-15-2019, 03:35 PM by rudolphyaber.)
(May-14-2019, 07:53 PM)snippsat Wrote: All should be string,so like this. The returned html has the correct title for the page between the <title> tags and so does the ApplicationName but still don't think I'm getting a good return, this is what I'm getting:
b'<html>\r\n
<head>\r\n
<title>APP</title>\r\n
</head>\r\n
<frameset name="jacadaframeset" frameborder="0" framespacing="0" rows="100%,*">\r\n
<frame name="jacadaframe" frameborder="0" marginheight="0" marginwidth="0" src="/Xhtml?JacadaApplicationName=APP"/>\r\n
</frameset>\r\n <noframes>\r\n
<p>Your browser doesn\'t support frames!<p>\r\n window.location.href="/Xhtml?JacadaApplicationName=APP";\r\n
</noframes>\r\n</html>\r\n'
Posts: 14
Threads: 6
Joined: Feb 2019
(May-14-2019, 07:53 PM)snippsat Wrote: All should be string,so like this. And I did make that change.
|