问题
I have a PyQt5 QWebEngineProfile with a QWebEngineUrlRequestInterceptor. This interceptor gives me access to the request before it it resolved. Is it possible to capture the response of every request intercepted without having to manually re-submit the request?
class WebEngineUrlRequestInterceptor(QWebEngineUrlRequestInterceptor):
def __init__(self, on_network_call):
super().__init__()
self.on_network_call = on_network_call
def interceptRequest(self, info):
self.on_network_call(info)
class PyQtWebClient(QWebEnginePage):
def __init__(self, url):
self.app = QApplication(sys.argv)
self.interceptor = WebEngineUrlRequestInterceptor(self.on_network_call)
self.profile = QWebEngineProfile()
self.profile.setRequestInterceptor(self.interceptor)
super().__init__(self.profile, None)
self.loadFinished.connect(self._on_load_finished)
self.html = ""
self.network_requests = {}
self.load(QUrl(url))
self.app.exec_()
def on_network_call(self, info):
# Something ...
def _on_load_finished(self):
self.toHtml(self.callable)
def callable(self, html_str):
self.html = html_str
self.app.quit()
PyQt5 Version: 5.11.2
来源:https://stackoverflow.com/questions/56923879/how-to-capture-the-response-of-a-request-intercepted-by-qwebengineurlrequestinte