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
tianxin8431
V2EX  ›  Python

python 无法获取 cookie

  •  
  •   tianxin8431 · 2015-05-30 19:07:49 +08:00 · 3902 次点击
    这是一个创建于 3224 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如题,最近学python,尝试做一个爬虫工具,但是使用cookielib.CookieJar()获取不到cookie,header也加上了,求解。爬的网站是http://czyw.cooco.net.cn

    8 条回复    2015-06-01 11:35:34 +08:00
    ChanneW
        1
    ChanneW  
       2015-05-30 20:05:28 +08:00
    是有cookies的,但是网站不要求登录,你记cookies有啥用。
    tianxin8431
        2
    tianxin8431  
    OP
       2015-05-30 20:07:50 +08:00
    @ChanneW 这个脚本的目的是为了自动扒题..然后那个网站是通过cookie来记录题目的编号的
    sivacohan
        3
    sivacohan  
       2015-05-30 20:12:42 +08:00 via Android
    你看一下cookie是哪个URL种的。
    tianxin8431
        4
    tianxin8431  
    OP
       2015-05-30 20:19:42 +08:00
    @sivacohan 试过了,还是不行。另外我测试的时候发现一个问题,用python请求163,qq等时也获取不到cookie,只有测试百度时候有。
    tigerstudent
        5
    tigerstudent  
       2015-05-30 20:29:13 +08:00
    用requests
    wibile
        6
    wibile  
       2015-05-30 20:40:13 +08:00
    @tigerstudent +10086,requests session
    xixijun
        7
    xixijun  
       2015-05-30 22:03:53 +08:00
    我看了下是有cookie的啊

    Cookie: AJSTAT_ok_pages=3; AJSTAT_ok_times=1; Hm_lvt_c8ad39b9579b4816dc8f6f805c190308=1432993700; Hm_lpvt_c8ad39b9579b4816dc8f6f805c190308=1432994293; bdshare_firstime=1432993700351
    julyclyde
        8
    julyclyde  
       2015-06-01 11:35:34 +08:00
    cookielib我记得是处理cookie格式的字符串的吧,并不是处理http协议的cookie header的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4864 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 09:54 · PVG 17:54 · LAX 02:54 · JFK 05:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.