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

用 requests 中的 post 正方教务系统后返回中的 text 中没有回应的文本?

  •  
  •   xyxc0673 ·
    xyxc0673 · 2016-05-30 21:54:39 +08:00 · 3529 次点击
    这是一个创建于 2859 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我在用 requests post 正方教务系统时,发现返回的 text 中没有什么用户名错误或者密码错误或者验证码错误之类的(以 js 嵌在源代码中)。
    网址是 http://jw.jluzh.com/
    想看下各位大神是否也是这样
    10 条回复    2016-05-31 08:43:23 +08:00
    xyxc0673
        1
    xyxc0673  
    OP
       2016-05-30 22:00:57 +08:00
    缩减的代码,验证码获取那段删除了
    import requests

    payload = {
    '__VIEWSTATE': "dDwyODE2NTM0OTg7Oz6axkqPO5u6m/sWzhMWZ6hy71QBYA==",
    'txtUserName': "123456",
    'TextBox2': "123456",
    'txtSecretCode':"1234",
    'RadioButtonList1': "学生",
    'Button1:': '',
    'lbLanguage': '',
    'hidPdrs': '',
    'hidsc': ''
    }

    headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Language': 'zh-CN,zh;q=0.8',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded',
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36"
    }

    r = requests.post("http://125.89.69.234/default2.aspx", headers = headers)
    print(r.text)
    est
        2
    est  
       2016-05-30 22:03:09 +08:00
    试试 r.content

    另外 requests 有 encoding 的坑。建议 r.encoding = None
    xyxc0673
        3
    xyxc0673  
    OP
       2016-05-30 22:11:01 +08:00
    @est 还是一样没有提示。。。
    pathletboy
        4
    pathletboy  
       2016-05-30 22:38:53 +08:00
    2 点
    1 、你 payload 没发出去
    2 、'Button1:': '', 这个多了个 :
    xyxc0673
        5
    xyxc0673  
    OP
       2016-05-30 22:41:30 +08:00
    @pathletboy 第二点!!!
    xyxc0673
        6
    xyxc0673  
    OP
       2016-05-30 22:41:45 +08:00
    @pathletboy 谢谢!
    cwlmxwb
        7
    cwlmxwb  
       2016-05-30 22:46:57 +08:00 via iPad
    验证码你是采用获取图片人工输入还是用图像识别
    xyxc0673
        8
    xyxc0673  
    OP
       2016-05-30 23:05:49 +08:00
    @cwlmxwb 手动输入
    atnoot
        9
    atnoot  
       2016-05-30 23:28:18 +08:00
    post 之后会自动跳转? 可以 dir 一下 r 的方法 爬过几个网站 貌似 post 之后会去 get 某个页面
    xyxc0673
        10
    xyxc0673  
    OP
       2016-05-31 08:43:23 +08:00
    @atnoot 现在问题是如果我输入错误的信息的 text 都会有相应提示,但是如果我输入正确的信息返回的 text 中是登录页面的代码,然后 cookies 也是空的,是什么原因?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5446 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:43 · PVG 14:43 · LAX 23:43 · JFK 02:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.