推荐学习书目
› 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
dancingbear
V2EX  ›  Python

如何给urllib2设置自己的cookie

  •  
  •   dancingbear · Jan 13, 2014 · 8150 views
    This topic created in 4639 days ago, the information mentioned may be changed or developed.
    针对一个url,已经通过 cookielib.CookieJar 以及urllib2.HTTPCookieProcessor(cj), 初始化过urllib2,可以正常使用。
    现在想给个这cj添加一些自己的cookie,应该怎么做?
    3 replies  •  1970-01-01 08:00:00 +08:00
    nervouna
        1
    nervouna  
       Jan 13, 2014
    建议使用第三方库 requests
    关于 Cookie:
    http://www.python-requests.org/en/latest/user/quickstart/#cookies

    urllib2 用起来有时候真的需要勇气……
    Lycnir
        2
    Lycnir  
       Jan 13, 2014
    支持LS
    dancingbear
        3
    dancingbear  
    OP
       Jan 14, 2014
    谢谢楼上,发现通过下列方式可以设置
    ck = cookielib.Cookie(version=0, name='cookie名称', value='值', port=None, port_specified=False, domain='www.abc.cn', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)
    cj.set_cookie(ck)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1177 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 17:29 · PVG 01:29 · LAX 10:29 · JFK 13:29
    ♥ Do have faith in what you're doing.