简体   繁体   English

幽灵不起作用

[英]Ghost doesn't work

I'm trying to use the example code from his own website and it does not work at all: 我正在尝试使用他自己网站上的示例代码,但它根本不起作用:

from ghost import Ghost
ghost = Ghost()

page, resources = ghost.open('http://google.com')

It's a quite simple example and this is the traceback : 这是一个非常简单的例子,这是追溯:

AttributeError: 'Ghost' object has no attribute 'open'

I'm working with Python 2.7, I have already installed PySide 1.2.4 for 64bits and I'm working in a machine with Windows7 我正在使用Python 2.7,我已经为64位安装了PySide 1.2.4而且我在使用Windows7的机器上工作

EDIT: 编辑:

I have tried this : 我试过这个:

import ghost
g = ghost.Ghost()
with g.start() as session:
     page, extra_resources = session.open("http://www.google.es")
     print page.http_status

And the traceback now is : 现在回溯是:

AttributeError: 'NoneType' object has no attribute 'http_status' but if I use the same code without the AttributeError:'NoneType'对象没有属性'http_status'但是如果我使用相同的代码而没有

print page.http_status print page.http_status

It shows no error 它没有显示错误

EDIT2: EDIT2:

Martijn Pieters give me this possible solution : Martijn Pieters给了我这个可能的解决方案:

from ghost import Ghost, Session

ghost = Ghost()

ghost = Session(ghost)

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

ghost.capture_to('screen_shot.png')

This code works but the screenshot is empty and the object has a 'none' type 此代码有效,但屏幕截图为空,对象具有“无”类型

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

~

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM