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

新手请教:如何用 python 请求动态网页,使其得到的内容和浏览器请求一样。

  •  
  •   twilight · May 31, 2016 · 6348 views
    This topic created in 3823 days ago, the information mentioned may be changed or developed.
    我试了 urllib 的 urlopen 和 requests 的 get ,得到的都只是静态的内容,网页里的表格内容没有得到。
    13 replies  •  2016-05-31 19:58:15 +08:00
    bytenoob
    bytenoob
    May 31, 2016
    1
    抓包分析请求
    wizardoz
    wizardoz
    May 31, 2016
    2
    表格里面的内容有可能是 ajax 或者 websocket 获取的,并不是在请求页面的时候就有。
    Patrick95
    Patrick95
    May 31, 2016❤️1
    3
    wizardoz
    wizardoz
    May 31, 2016
    4
    如果是 ajax 那好办,用浏览器的 F12 看看它请求了什么东西就可以了。
    如果是 websocket 就难办了。
    mrwangrj
    mrwangrj
    May 31, 2016❤️2
    5
    phantomjs
    SlipStupig
    SlipStupig
    May 31, 2016
    6
    @wizardoz iframe ajax 表单字段随机化,有没办法不开浏览器能直接跑通
    twilight
    twilight
    OP
    May 31, 2016
    7
    感谢各位热心回复。

    搜了搜,好像有用 PythonWebKit 或 PyQtWebKit 来做的。
    jinfeng333
    jinfeng333
    May 31, 2016
    8
    phantomjs +1
    mingyuejingque
    mingyuejingque
    May 31, 2016❤️1
    9
    phantomjs + 2 , 配合 casperjs 可以搞很多小动作,嘿嘿嘿
    tkpc
    tkpc
    May 31, 2016
    10
    system("google-chrome")
    jiezhi
    jiezhi
    May 31, 2016❤️1
    11
    selenium + phantomjs 呢
    xinali
    xinali
    May 31, 2016❤️1
    12
    有两种思路,一种是如果你想分析 js 处理后的网页源码可以使用 selenium+phantomjs ,但是有坑在携带 cookie ,修改 header 等方面。一种是用 requests 获取到网页未经 js 处理的代码,之后分析网页的 js 处理情况并结合 nodejs 对网页进行二次加工,这样而且可以极大的加快你的处理速度,具体的可以看我写的这个 http://xinali.github.io/2016/05/22/python%E5%A4%84%E7%90%86js%E7%BD%91%E9%A1%B5/
    ila
    ila
    May 31, 2016 via Android
    13
    @Patrick95 赞同+1
    官方更新后百度得到的资料还是旧的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2334 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 12:43 · PVG 20:43 · LAX 04:43 · JFK 07:43
    ♥ Do have faith in what you're doing.