本文介绍了使用Ghost.py抓取屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是不起作用的简单程序

Here is the simple program which does not work

from ghost import Ghost

ghost = Ghost(wait_timeout=40)
page, extra_resources = ghost.open("http://samsung.com/in/consumer/mobile-phone/mobile-phone/smartphone/")
ghost.wait_page_loaded()
n=2;
links=ghost.evaluate("alist=document.getElementsByTagName('a');alist")
print links

错误IS:引发异常(超时消息)

ERROR IS: raise Exception(timeout_message)

异常:无法加载请求的页面

Exception: Unable to load requested page

程序有问题吗?

推荐答案

似乎人们在向您报告类似的问题,但并没有得到任何解释(例如: https://github.com/jeanphix/Ghost.py/issues/26 )

Seem like people are reporting similar issues to yours, without really getting any explanation (for example: https://github.com/jeanphix/Ghost.py/issues/26)

将评估行调整为以下内容,这是ghost.py文档所引用的:

Adjust the evaluate line to the following, which is referenced by a ghost.py documentation:

links = gh.evaluate("""
                        var links = document.querySelectorAll("a");
                        var listRet = [];
                        for (var i=0; i<links.length; i++){
                            listRet.push(links[i].href);
                        }
                        listRet;
                    """)

这篇关于使用Ghost.py抓取屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 20:25