4

我正在尝试使用他自己网站上的示例代码,但它根本不起作用:

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' 但如果我使用相同的代码而没有

打印页面.http_status

它显示没有错误

编辑2:

Martijn Pieters 给了我这个可能的解决方案:

from ghost import Ghost, Session

ghost = Ghost()

ghost = Session(ghost)

ghost.open('http://www.google.com')

ghost.capture_to('screen_shot.png')

此代码有效,但屏幕截图为空,并且对象具有“无”类型

4

1 回答 1

2
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')
~                                         

~

于 2017-11-04T21:03:18.837 回答