请教个 Requests 的问题

2014-03-04 20:08:44 +08:00
 cruelcage
我想用Requests模拟登陆http://bbs.weiphone.com

我看了下登陆要用到的cookie是xIka_2132_saltkey和xIka_2132_auth

但是我post后得到的response.cookies里面没有这两个cookie,有人能告诉我漏了什么吗?

login_url = 'http://passport.weiphone.com/?r=user/loginProcess'
user = 'xxxx'
password = 'xxxx'
user_info = {'Kaf_Model_Form_Login[login]': user,
'Kaf_Model_Form_Login[password]': password,
'Kaf_Model_Form_Login[remember]': 0 }
login = requests.post(login_url, data=user_info)
for cookie in login.cookies:
print (cookie.name, cookie.value)

output: ('PHPSESSID', 'vc6v382ibq656ftmj4ej0jef26')
3315 次点击
所在节点    Python
8 条回复
allenforrest
2014-03-04 21:37:15 +08:00
为什么不用session?完全不管cookies了
clino
2014-03-04 22:23:22 +08:00
如楼上所说,requests某版本以后response里就开始没有cookie了,session里一直都是有的
http://docs.python-requests.org/en/latest/api/#request-sessions
cruelcage
2014-03-04 23:38:32 +08:00
@allenforrest
@clino
多谢,但是还是拿不到我要的cookie
post后有个自动跳转的链接,不明白为什么会自己加上3个参数http://bbs.weiphone.com/api/uc.php?time=xxx&code=xxx&_=xxx,主要是那个code
binux
2014-03-04 23:44:47 +08:00
print login.status_code, login.headers
cruelcage
2014-03-05 08:26:03 +08:00
@binux headers里面也没有啊

'set-cookie': 'PHPSESSID=01d2bjtr95sk4otmok772rqss2; path=/, PHPSESSID=v591fg9v12a2hiv71mn7o70837;
ushuz
2014-03-05 08:50:13 +08:00
@cruelcage
状态码是3xx么?看headers里的location。2xx看response里有没有js跳转。
allenforrest
2014-03-05 16:04:29 +08:00
@cruelcage 这个不是 cookie 吧?
cruelcage
2014-03-05 17:21:49 +08:00
@ushuz headers里面没有location,跳转的js我再研究下


@allenforrest 是有个跳转的url,不知道参数是怎么来的。。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/102879

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX