等待网站使用WebKitGTK +完全加载 [英] Waiting for a website to load completely with WebKitGTK+

查看:126
本文介绍了等待网站使用WebKitGTK +完全加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
Webkit GTK:确定何时完成文档加载

Possible Duplicate:
Webkit GTK: Determine when a document is finished loading

我想使用WebKitGTK +来获取网站的HTML内容,以自动处理javascript重定向.

I want to fetch a website's HTML contents with WebKitGTK+ to handle the javascript redirections automatically.

我正在使用以下Python代码:

I am using the following Python code:

def scanURL(domain, retries=3):
    status = 0
    loading = 0

    browser = webkit.WebView()
    browser.open('http://' + domain)
    while browser.get_load_status() < 2:
        continue

    if browser.get_load_status() == 4:
        if retries > 0:
            return scanURL(domain, retries - 1)
        return 'Failed'

    return 'Success'

该网站加载正常,但是有一些特殊的网站正在重定向到重定向到其他地方的网页,我尝试将load-finished事件连接到一个函数,并且该事件被调用了两次.

The website loads fine, but there are some special websites which are redirecting to a webpage redirecting somewhere else, I've tried to connect the load-finished event to a function, and it's called twice.

有没有办法知道WebKit何时完全加载了网页?

Is there a way to know when WebKit has completely loaded a webpage ?

我怎么知道WebKit是否仍在执行一些JavaScript代码?

How can I know if WebKit is still executing some JavaScript code ?

推荐答案

没有确定的方法可以以编程方式完成所有网站的任务,因为在某些页面中,这些重定向是使用javascript启动的,通常是由 setTimeout启动的(在n秒后),并且没有内置方法可以扫描此类怪癖".但是,如果您要解析一组已知的网站(您肯定知道会发生此类重定向),则可以创建具有所需重定向秒数的这些URL的列表.触发初始loadFinished后,可以启动QTimer,将其信号连接到将再次触发loadFinished的函数,因此在等待结果时一定会开始下一个页面加载. 等待页面结果,直到没有新的loadStarted信号触发并且无需重新进行重定向为止.

There is no sure way to programatically accomplish that task for all websites, as there are pages where those redirections are initiated with javascript, often started by setTimeout after n-seconds, and there is no built-in method to scan for such "quirks". However if you are parsing a known group of websites, where you surely know that such redirections will happen, you can create a list of those urls with the required number of seconds after which the redirection will happen. After an initial loadFinished is fired, you can start a QTimer, connect it's signal to a function which will fire loadFinished again, so the next page load will surely start while you're waiting for the result. Wait for the page result until there are no new loadStarted signals fired and no redirection needs to be done again.

这篇关于等待网站使用WebKitGTK +完全加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆