Ghost.py安装过程
2016-02-22
快速安装
#获取最新apt仓库
sudo add-apt-repository ppa:pyside
sudo apt-get update
#安装pip环境
apt-get install python-pip
#安装pyside环境
#apt-get install build-essential cmake libqt4-dev libxml2-dev libxslt1-dev python-dev qtmobility-dev
#安装pyside
apt-get install python-pyside
apt-get install xvfb
#pip install pyside
pip install flask
#安装Ghost
git clone git://github.com/carrerasrodrigo/Ghost.py.git
cd Ghost.py
python setup.py install
安装中文字体:
复制windows下的字体文件到/usr/share/fonts/目录下
执行fc-cache刷新字体缓存
实例
#!/usr/bin/env python
from ghost import Ghost
url = "http://malu.me/"
g = Ghost(cache_size=10,viewport_size=(1360,768))
page, page_name = g.create_page()
page_resource = page.open(url, wait_onload_event=True)
page.wait_for_selector("#quotation ul li")
page.capture_to("malu.png")
文档
关于pyside环境安装:https://github.com/PySide/BuildScripts
文档一:http://jeanphix.me/Ghost.py/
文档二:http://carrerasrodrigo.github.io/Ghost.py/
另外一个版本Ghost.py
快速安装
#先安装上面的python-pyside
#通过pip安装
pip install ghost.py --pre
实例
#!/usr/bin/env python
from ghost import Ghost
url = 'http://malu.me/'
g = Ghost()
with g.start(download_images=True,wait_timeout=60) as s:
page, extra_resources = s.open(url,user_agent='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2526.106 Safari/537.36')
s.set_viewport_size(1360,768)
#s.wait_for_selector('#quotation ul li')
s.sleep(3)
print page.content
s.capture_to("malu.png")
文档
文档一:http://ghost-py.readthedocs.org/en/latest
注:
个人用户字体文件在~/.local/share/fonts
系统字体文件在/usr/share/fonts
字体配置文件在/etc/fonts/