第一次在这里发帖,如有任何礼仪方面的错误,请事先谅解。
我正在使用Python 3和Requests库编写代码,在网站上登录后应该会返回给我另一个页面。
我使用Google Chrome开发者工具查看了必须包含在有效负载中的表单数据,我认为问题的原因是org.apache.struts.taglib.html.TOKEN,它在每个表单提交时都是唯一的。
有人知道如何解决这个问题吗?还是另一个问题?当前它让我返回一个页面,告诉我“详细信息不正确”。但我已经手动使用这些详细信息登录了该网站,以记录登录期间发送的数据。
我的代码如下。
import requests
with requests.Session() as s:
payload = {"org.apache.struts.taglib.html.TOKEN": this is unique on each form submission,
"loginRegNo": xxxxxxx, "loginPin": xxxxxx}
headers = {"Accept": "text/html",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Content-Length": "105",
"2Content-Type": "application/x-www-form-urlencoded",
"Cookie": "JSESSIONID=xxxxxx,
"Host": "www.website.ie",
"Origin": "https://www.website.ie",
"Pragma": "no-cache",
"Referer": "https://www.website.ie/OMT/omt.do",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36}"
}
p = s.post("https://www.website.ie/OMT/omt.do", data=payload, headers=headers, cookies=s.cookies)
# print the status code to see if it's successful
print(p.status_code)
r = s.get("https://www.website.ie/OMT/login.do", cookies=s.cookies)
print(r.text)
print(r.url)
print(r.status_code)