0

我对此有一些困难,但基本上将页面加载到 QWebView 是否有可能获取在呈现页面过程中加载的内容的事件?

我正在使用 PySide,所以假设你已经有一个 QWebView 作为 'w'

w.load('http://www.unicorns-are-awesome.com/index.html')

该 index.html 的内容如下所示:

<html>
    ...
    <head> 
         <script src="something.js">
    </head>
    <body>
         <img src="unicorns.jpg">
    </body>
</html>

QWebView 必须同时下载something.jsunicorns.jpg - 但到目前为止,似乎没有任何明显的方式来获取这些从属下载的 downloadRequest 事件。

w.page() 发出“downloadRequest”的唯一时间是当您更改 QtWebView 中的 URL 时,即您只能获取“位置”栏中的内容的更新。

网页在 QtWebView 中下载的每个元素如何获得通知?

更新: NetworkAccessManager 实施:

from MainWindow import MainWindow
from PySide.QtGui import QApplication
from PySide.QtCore import QCoreApplication
from PySide.QtWebKit import QWebView, QWebSettings
from PySide.QtNetwork import QNetworkReply

class TransferMonitor(object):

    def __init__(self):
        a = MainWindow._instance # "singleton"
        b = a.findChild(QWebView, "browser")
        nm = b.page().networkAccessManager()
        nm.finished[QNetworkReply].connect( self.dump_url )

    def dump_url(self, reply):
        # This is probably unnecessary, but
        # I wanted to be 100% sure that every get
        # was 'fresh'. 

        QWebSettings.clearMemoryCaches()

        # For now all we really do is just dump URLs 
        # as they're processed. Perhaps later we will intercept.

        print reply.url().toString()
4

1 回答 1

1

你需要实现一个QNetworkAccessManager,覆盖createRequest(),然后调用QWebPage::setNetworkAccessManager()。我不确定这在 PySide 中是否可行。

于 2012-01-18T16:24:10.400 回答