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

获取一个被打开网页中的一个 js 变量,用什么最简单

  •  
  •   quietin · Dec 14, 2015 · 4031 views
    This topic created in 3937 days ago, the information mentioned may be changed or developed.

    这个变量在 DOM 里找不到的惹,所以不能用正则匹配或者获取内容的方式,比如 window.xx

    Ghost.py试了一下,崩溃,而且为了装它要先装 PySide, 编译老费劲了

    自己先看了一下,PyQt,里面有 webkit 封装,或者PyV8好像也可以,还有调用 phantomjs 等等,但还是要来问问,有没有更简单的方法(因为懒)

    12 replies  •  2015-12-15 16:38:41 +08:00
    just1
        1
    just1  
       Dec 14, 2015 via Android
    正则表达式吧
    dofy
        2
    dofy  
       Dec 15, 2015 via iPhone
    需求是什么,应用场景?
    pynix
        3
    pynix  
       Dec 15, 2015
    dom 里找不到应该是 XHR 获取的吧。 chrome 看看 network 呗。。。
    arsenal4
        4
    arsenal4  
       Dec 15, 2015
    chrome -> Console
    imt
        5
    imt  
       Dec 15, 2015
    chrome -> Console +1
    quietin
        6
    quietin  
    OP
       Dec 15, 2015
    @dofy 脚本模拟登录,需要这个变量
    quietin
        7
    quietin  
    OP
       Dec 15, 2015
    @taizhenhua1987
    @imt 要自动化的。。人工看就没啥意思了
    quietin
        8
    quietin  
    OP
       Dec 15, 2015
    pyv8 装不上。。。谷哥也帮不了,天啊
    imt
        9
    imt  
       Dec 15, 2015
    明白你的意思了,phantomjs,学习一下.必须借助 webkit,brower 组件才行吧,个人理解.
    0192
        10
    0192  
       Dec 15, 2015
    quietin
        11
    quietin  
    OP
       Dec 15, 2015
    @imt 是的,但是类似的库不一定能得到 Js 变量,不过我好像已经在网页中找到这个变量了,虽然得要拼装
    quietin
        12
    quietin  
    OP
       Dec 15, 2015
    @imt selenium 可以直接控制 phantomjs ,很酸爽
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2590 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 08:12 · PVG 16:12 · LAX 01:12 · JFK 04:12
    ♥ Do have faith in what you're doing.