美文网首页Python编程
Linux/OSX 折腾Ghost.py记录

Linux/OSX 折腾Ghost.py记录

作者: 止念观息 | 来源:发表于2016-10-19 21:09 被阅读112次

    最近要用一下Python爬虫,webkit相关的东西,找到Ghost.py这玩意儿,看使用方法感觉还不错,开整,坑真多。

    先是在OSX上面安装,官方文档提供的方法有点过时,磕磕绊绊总算安装成功了。

    首先安装qt:

    brew install qt

    然后安装pyside或者pyqt (貌似二选一即可)

    pip install PySide

    或者

    brew install pyqt

    (貌似pip安装也可以)

    最后安装ghost:

    pip install Ghost.py

    注:过程当中可能会需要sip, cmake等依赖

    又在Ubuntu 14上安装了一次,过程有些不一样:

    apt-get install python-pip

    apt-get install sip-dev

    apt-get install cmake

    sudo apt-get install libxext6 libxext-dev libqt4-dev libqt4-gui libqt4-sql qt4-dev-tools qt4-doc qt4-designer qt4-qtconfig "python-qt4-*" python-qt4

    pip install ghost.py --pre

    apt-get install xvfb

    折腾下来感觉Linux和Python坑都不少啊~

    测试代码:

    from ghost import Ghost

    client = Ghost()

    ghost = client.start()

    page,res = ghost.open('https://www.baidu.com')

    assert page.http_status==200

    result,res = ghost.evaluate("document.getElementById('su').getAttribute('value');")

    print(result)                     #Linux输出方式

    print(result.toUtf8())        #OSX输出方式

    相关文章

      网友评论

        本文标题:Linux/OSX 折腾Ghost.py记录

        本文链接:https://www.haomeiwen.com/subject/sjugjttx.html