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

[第三问] 模拟登陆 post XML 格式参数和自动重定向

  •  
  •   Huayx9 · Aug 1, 2016 · 3108 views
    This topic created in 3709 days ago, the information mentioned may be changed or developed.

    感觉写这次电信网上营业厅的爬虫,把坑踩了个遍,还是不能完美解决各种问题。

    通过抓包,整个登陆过程中的 http 的详细过程,大致如下

    • 一.向 LoginServlet 这个 url post 登陆表单;状态码 200
    • 二.再向 Login 这个 url post 一组 XML 参数;状态 302
    • 三.302 重定向三次,指向账号登陆成功页面
    • 四.get 登陆成功页面,完成登陆过程

    ——————————————————

    *0.LoginURL

    *1.POST|(LoginServlet) --------- 登陆 form --------- referer:0.LoginURL--------- status_code:200

    *2.POST ---------SSORuquetXML --------- refererr:LoginServlet ---------location:3--------status_code:302

    *3.GET --------- referer:LoginServlet ---------location:4--------- status_code:302

    *4.GET ---------referer:LoginServlet --------- location:5 --------- status_code:302

    *5.GET --------- referer:LoginServlet --------- status_code:200

    *6.GET ---------acount/init.action --------- referer:5

    —————————————————— 我遭不住了。。。

    1.XML 格式怎么 post , python 实现(是以字典格式,百度了发现都是解析 xml 文件之类的)?

    2.XML 中有些 ID 参数是怎么生成的(审查元素,并没有相关的 JS 进行处理),我比对了不同账号,发现就一些 ID 参数不同?

    3.在 request.session()中, cookies 并不能自动管理?(浏览器抓包是很多 cookies ,而代码实现,只有一条或者没有 Cookies )

    再踩几个坑,再解决不了。。。我就放弃,感谢大家最近几天的耐心解答

    2 replies  •  2016-08-01 18:13:22 +08:00
    Huayx9
        1
    Huayx9  
    OP
       Aug 1, 2016
    在 post 操作之后,后面如果有重定向,能由 reuqests 自动完成
    Huayx9
        2
    Huayx9  
    OP
       Aug 1, 2016
    我是傻逼。。你们别回复我
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2535 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:26 · PVG 18:26 · LAX 03:26 · JFK 06:26
    ♥ Do have faith in what you're doing.