V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
fyl00
V2EX  ›  Python

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

  •  
  •   fyl00 · 2015-03-16 15:47:08 +08:00 · 3844 次点击
    这是一个创建于 3524 天前的主题,其中的信息可能已经有所发展或是发生改变。
    之前做了一个导出虾米收藏歌曲的小脚本,但是发现虾米会对未登录用户进行限制。所以尝试用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,
    }
    1 条回复    2015-03-17 02:10:35 +08:00
    latyas
        1
    latyas  
       2015-03-17 02:10:35 +08:00
    为什么不尝试使用一下requests呢 :-)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5375 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:13 · PVG 15:13 · LAX 23:13 · JFK 02:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.