python爬取时post问题
本帖最后由 ciker_li 于 2021-1-22 21:29 编辑我想爬取孩子的考试成绩,网址http://60.223.230.87:9090/LSXQ
在网页正常浏览时,点击登陆,post学号密码后,会得到一个SET-Cookie :LS_UserInfo=xyXqmvT2gYFgnQ45q/hdeTUJufNqTrWP
但我自己写的post,却得不到。
用Fiddler抓取post帧数据,构造的跟正常浏览的一模一样,但返回缺没有那个SET-Cokkie,请问是为什么??
这 是我 的代码:
import requests
s = requests.Session()
url1 = "http://60.223.230.87:9090/LSXQ"
res1 = s.get(url = url1)
url2 = "http://60.223.230.87:9090/LSXQ/account/Logon"
data = {"name":"2021154032","pwd":"588266","ibg":"0"}
cookie = "ASP.NET_SessionId=" + res1.cookies['ASP.NET_SessionId']+";__tins__20061455=%7B%22sid%22%3A%201611315255917%2C%20%22vd%22%3A%204%2C%20%22expires%22%3A%201611317104026%7D; __51cke__=; __51laig__=4"
header={
"Accept":"text/html, */*; q=0.01",
"X-Requested-With":"XMLHttpRequest",
"Accept-Language":"zh-CN,zh;q=0.9",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Origin": "http://60.223.230.87:9090",
"Referer": "http://60.223.230.87:9090/LSXQ/",
"Cookie":cookie,
"Connection":"keep-alive"
}
res2 = s.post(url=url2,data=data,headers =header)
密码不正确,无法复现问题。 闲月疏云 发表于 2021-1-22 21:14
密码不正确,无法复现问题。
原来是密码写错了
SET-Cookie 一般会在你首次get请求的response.headers 里面返回 url2 = "http://60.223.230.87:9090/LSXQ/account/Logon"
Login? {:301_998:}遇事不决 selenium
页:
[1]