我正在尝试使用他自己网站上的示例代码,但它根本不起作用:
from ghost import Ghost
ghost = Ghost()
page, resources = ghost.open('http://google.com')
这是一个非常简单的例子,这是追溯:
AttributeError: 'Ghost' object has no attribute 'open'
我正在使用Python 2.7,我已经为64位安装了PySide 1.2.4而且我在使用Windows7的机器上工作
编辑:
我试过这个:
import ghost
g = ghost.Ghost()
with g.start() as session:
page, extra_resources = session.open("http://www.google.es")
print page.http_status
现在回溯是:
AttributeError:’NoneType’对象没有属性’http_status’但是如果我使用相同的代码而没有
print page.http_status
它没有显示错误
EDIT2:
Martijn Pieters给了我这个可能的解决方案:
from ghost import Ghost, Session
ghost = Ghost()
ghost = Session(ghost)
ghost.open('http://www.google.com')
ghost.capture_to('screen_shot.png')
此代码有效,但屏幕截图为空,对象具有“无”类型
最佳答案
from ghost import Ghost
ghost = Ghost()
with ghost.start() as session:
page, extra_resources = session.open("http://www.google.de")
session.set_viewport_size(1920,1080)
session.capture_to('test.png')
~
〜