建 Cookies 模拟登录虾米之后再打开虾米链接后 headers 里面没有 Cookies 了

2015-03-16 15:47:08 +08:00
 fyl00
之前做了一个导出虾米收藏歌曲的小脚本,但是发现虾米会对未登录用户进行限制。所以尝试用cookiejar 和模拟登录试试,登录成功了再抓还是被403了,于是就去抓 Response 的 headers 看看有没有 Cookies ,结果发现不带了,但是登录前的 headers 是有的。而且 Cookies 里面其实是有关于xiami.com 的项目


登录前 [('Server', 'Tengine'), ('Date', 'Mon, 16 Mar 2015 07:14:01 GMT'), ('Content-Type', 'text/html; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Connection', 'close'), ('Vary', 'Accept-Encoding'), ('Set-Cookie', '_xiamitoken=222a35faf32ebde011cd3259dbf04e43; expires=Sun, 22-Mar-2015 21:00:00 GMT; path=/; domain=.xiami.com'), ('Set-Cookie', '_unsign_token=eceb1f81efed5d505dfdb6c832d3a719; expires=Mon, 14-Mar-2016 21:00:00 GMT; path=/; domain=.xiami.com; httponly'), ('Cache-Controli', 'must-revalidate'), ('Pragma', 'no-cache')]

登录后 [('Server', 'Tengine'), ('Date', 'Mon, 16 Mar 2015 07:14:12 GMT'), ('Content-Type', 'text/html; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Connection', 'close'), ('Vary', 'Accept-Encoding'), ('Cache-Controli', 'must-revalidate'), ('Pragma', 'no-cache')]

Cookies 的值
[ 0 ] <Cookie havana_tgc=eyJpc29sYXRlZFRnYyI6eyJhY2NJbmZvcyI6eyIxMiI6eyJtZW1iZXJJZCI6MjQ2MDYxNDgyNywiYWNjZXNzVHlwZSI6MywidGd0SWQiOiIxYnhybkpNUWFydE5qc0FPZzY0dmRMQSJ9fX0sInRnYyI6eyJzZXNzaW9ucyI6eyIxIjp7ImFjY291bnRJbmZvIjp7ImxvY2FsIjpmYWxzZSwibWVtYmVySWQiOjI0NjA2MTQ4MjcsInNpdGUiOjEyLCJtb2JpbGUiOiIxODYxMDM3OTM1NCIsInRhb2Jhb05pY2siOiJwbWRvZyIsImNidUxvZ2luSWQiOiJwbWRvZyIsImFjY2Vzc1R5cGUiOjN9fX0sInRndElkIjoiMWxNS01sak1mNHNnMlRpYWRqTzZqZWciLCJkZWZhdWx0U2lkIjoxLCJhY3RpdmVTaWRzIjp7IjAiOjF9LCJmaXJzdFNpZCI6MX19 for .passport.alipay.com/>
[ 1 ] <Cookie _unsign_token=eceb1f81efed5d505dfdb6c832d3a719 for .xiami.com/>
[ 2 ] <Cookie _xiamitoken=222a35faf32ebde011cd3259dbf04e43 for .xiami.com/>
[ 3 ] <Cookie member_auth=gmnMGYkf7mo2hPCXRYtkcXdJteGHHjbUwo4Ehr4r4lZ2cI8MY4SskquVSgtM2CWRr2FfSenDigJP for .xiami.com/>
[ 4 ] <Cookie user=48040527%22pmdog%22%220%2222%22%3Ca+href%3D%27%2Fwebsitehelp%23help9_3%27+%3Edo%3C%2Fa%3E%220%220%228%22375d663050%221426490051 for .xiami.com/>
[ 5 ] <Cookie JSESSIONID=EF6YBKMUO2-VOMXRD42K6WJZ2DK246V1-KE9CJB7I-QAUMK for passport.alipay.com/>
[ 6 ] <Cookie cookie_seed=1 for passport.alipay.com/>
[ 7 ] <Cookie last_ae_xiami=taobao for passport.alipay.com/>
[ 8 ] <Cookie last_cc=ED8E288CDB74AA4BCB7E for passport.alipay.com/>
[ 9 ] <Cookie tmp0=eNrz4A12DQ729PeL9%2FV3cfUxiK3OTLFScnUzi3Ty9g31N9IN8%2FeNCHIxMfI2C%2FeKMnLxNjIxCzPU9Xa1dPZyMvfUDXQM9fVW0kkusTI0MTIzsTQwMDEytzDQSUxGE8itsDKojQIAmSgdIg%3D%3D for passport.alipay.com/>



想问下这是什么原因造成的?
代码地址: http://pan.baidu.com/s/1bnliCu7
**运行的之前要用填绑定了虾米的淘宝账号账号密码**
postdata = {
#绑定了虾米的淘宝账号
'loginId': ,
#绑定了虾米的淘宝账号密码
'password': ,
'appName': 'xiami',
'appEntrance': 'taobao',
'hsid': soup.find('input', {'name': 'hsid'})['value'],
'cid': soup.find('input', {'name': 'cid'})['value'],
'rdsToken': soup.find('input', {'name': 'rdsToken'})['value'],
'umidToken': soup.find('input', {'name': 'umidToken'})['value'],
'_csrf_token': soup.find('input', {'name': '_csrf_token'})['value'],
'checkCode': captcha,
}
3844 次点击
所在节点    Python
1 条回复
latyas
2015-03-17 02:10:35 +08:00
为什么不尝试使用一下requests呢 :-)

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

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

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

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

© 2021 V2EX