推荐学习书目
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 · Apr 23, 2015 · 3928 views
    This topic created in 4071 days ago, the information mentioned may be changed or developed.
    在爬学校网站,先进入登录界面后再打开成绩页面,发现只有成绩页面的输出为空,我想知道我的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 replies    2015-04-28 03:46:05 +08:00
    tikazyq
        1
    tikazyq  
       Apr 24, 2015   ❤️ 1
    看看r.status_code和r.content,去网站上看看是不是用了javascript读入内容,requests不能读js
    kaneg
        2
    kaneg  
       Apr 24, 2015 via iPhone
    用Firefox的调试神器firebug
    ca1n
        3
    ca1n  
       Apr 25, 2015
    user-agent这个不设定的话发送的就是user-agent:python2/3.。。什么什么的了 有的服务器拒绝这样的ua
    jhony
        4
    jhony  
    OP
       Apr 27, 2015
    谢谢楼上几位,我查看了chrome里面Resource项,里面相关网页的session均为空,只有cookie项,那就是意味着我根本不需要调用session,直接调用发送cookie的函数就好了吧?
    tikazyq
        5
    tikazyq  
       Apr 28, 2015
    chrome点开看network看response,把http://jwweb.yzu.edu.cn:8082/xsxt/xsxt.jsp这个requst的内容看看
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5192 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 09:22 · PVG 17:22 · LAX 02:22 · JFK 05:22
    ♥ Do have faith in what you're doing.