![](/img/trans.png)
[英]Trying to log into PowerSchool website using Mechanize (Python) - failing
[英]Log Into Powerschool Using Python Requests
def get_Auth():
USERNAME = User.get("1.0", END)
PASSWORD = Pass.get("1.0", END)
print(USERNAME)
print(PASSWORD)
url = 'https://ps.lphs.net/public/home.html'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.92 Safari/537.36 Vivaldi/1.6.689.34'}
g = requests.get(url)
soup = BeautifulSoup(g.content)
'Find The Values'
PSTOKEN = None
CONTEXTDATA = None
for input in soup.find_all('input')[0:1]:
PSTOKEN = input.get('value')
print(PSTOKEN)
for input in soup.find_all('input')[1:2]:
CONTEXTDATA = input.get('value')
print(CONTEXTDATA)
payload = {
'pstoken': PSTOKEN,
'contextData': CONTEXTDATA,
'dbpw': '',
'translator_username': '',
'translator_password': '',
'translator_ldappassword': '',
'returnUrl': 'https://ps.lphs.net/guardian/home.html',
'serviceName': 'PS Parent Portal',
'serviceTicket': '',
'pcasServerUrl': '\ /',
'credentialType': 'User Id and Password Credential',
'account': USERNAME,
'pw': PASSWORD,
'translatorpw': ''
}
r = requests.post(soup, data=payload)
print(r)
我正在尝试登录PowerSchool,并从需要登录的页面上抓取成绩。 我一直在观看视频,无法弄清为什么它不起作用。 我有一个Tkinter窗口,询问我的用户名和密码,然后使用该窗口登录该网站。 但是,当我运行它时,我得到的只是登录页面源代码。 这是“检查”元素下“网络”选项卡的图片。
我不确定这是怎么回事,我已经研究了一段时间。 提前致谢!
我没有要测试的帐户,但是您当前的方法有很多错误:
密码( pw
字段)通过以下函数( 在此处定义)进行散列:
function doPCASLogin(form) { var originalpw = form.pw.value; var b64pw = b64_md5(originalpw); var hmac_md5pw = hex_hmac_md5(pskey, b64pw) form.pw.value = hmac_md5pw; form.dbpw.value = hex_hmac_md5(pskey, originalpw.toLowerCase()) if (form.ldappassword!=null) { // LDAP is enabled, so send the clear-text password // Customers should have SSL enabled if they are using LDAP form.ldappassword.value = originalpw; // Send the unmangled password } // Translator Login var translatorpw = form.translatorpw.value; var i = translatorpw.indexOf(";"); if (i < 0) { form.translator_username.value = translatorpw; form.translator_password.value = ""; } else { form.translator_username.value = translatorpw.substring(0,i); translatorpw = translatorpw.substring(i+1); // Get the password translatorpw2 = translatorpw; translatorpw = b64_md5(translatorpw); // Added in move to pcas form.translator_password.value = hex_hmac_md5(pskey, translatorpw); if (form.translator_ldappassword!=null) { // LDAP is enabled, so send the clear-text password // Customers should have SSL enabled if they are using LDAP form.translator_ldappassword.value = translatorpw2; // Send the pw for LDAP } } return true; }
您每次发出请求时都不能拥有相同的令牌值。 您必须从实际表单中获取令牌值。 这意味着您需要首先“获取” home.html
,提取令牌值,然后在“ POST”请求中使用它们。
对于第二个问题,您可能想要尝试mechanize
或mechanicalSoup
,这些操作将自动“自动填充”其余表单字段。 但是,他们无法执行JavaScript,这在这种情况下非常重要。
如果要避免处理所有这些问题,请查看浏览器自动化和selenium
软件包 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.