最近要用一下Python爬蟲,webkit相關(guān)的東西,找到Ghost.py這玩意兒,看使用方法感覺還不錯(cuò),開整,坑真多。
先是在OSX上面安裝,官方文檔提供的方法有點(diǎn)過時(shí),磕磕絆絆總算安裝成功了。
首先安裝qt:
brew install qt
然后安裝pyside或者pyqt (貌似二選一即可)
pip install PySide
或者
brew install pyqt
(貌似pip安裝也可以)
最后安裝ghost:
pip install Ghost.py
注:過程當(dāng)中可能會(huì)需要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坑都不少啊~
測(cè)試代碼:
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輸出方式