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

requests 库调用 Session 方法打开关联网站,输出却为空?

  •  
  •   jhony · 2015-04-23 18:05:58 +08:00 · 3118 次点击
    这是一个创建于 3304 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在爬学校网站,先进入登录界面后再打开成绩页面,发现只有成绩页面的输出为空,我想知道我的session方法哪儿用错了?附上代码
    import requests
    from bs4 import BeautifulSoup
    s=requests.Session()
    payload={'userId':'***','userPass':'****'}
    soup=s.post('http://jwweb.yzu.edu.cn:8082/xsxt/xsxt.jsp',data=payload)#先进入登录界面
    r=s.get('http://58.192.142.134:7777/pls/wwwbks/bkscjcx.curscopre')#进入关联界面
    print r.
    5 条回复    2015-04-28 03:46:05 +08:00
    tikazyq
        1
    tikazyq  
       2015-04-24 02:26:41 +08:00   ❤️ 1
    看看r.status_code和r.content,去网站上看看是不是用了javascript读入内容,requests不能读js
    kaneg
        2
    kaneg  
       2015-04-24 13:39:55 +08:00 via iPhone
    用Firefox的调试神器firebug
    ca1n
        3
    ca1n  
       2015-04-25 14:48:49 +08:00
    user-agent这个不设定的话发送的就是user-agent:python2/3.。。什么什么的了 有的服务器拒绝这样的ua
    jhony
        4
    jhony  
    OP
       2015-04-27 20:48:47 +08:00
    谢谢楼上几位,我查看了chrome里面Resource项,里面相关网页的session均为空,只有cookie项,那就是意味着我根本不需要调用session,直接调用发送cookie的函数就好了吧?
    tikazyq
        5
    tikazyq  
       2015-04-28 03:46:05 +08:00
    chrome点开看network看response,把http://jwweb.yzu.edu.cn:8082/xsxt/xsxt.jsp这个requst的内容看看
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4143 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 05:13 · PVG 13:13 · LAX 22:13 · JFK 01:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.