Как перехватить ответ на запрос, перехваченный QWebEngineUrlRequestInterceptor? - PullRequest
0 голосов
/ 07 июля 2019

У меня есть PyQt5 QWebEngineProfile с QWebEngineUrlRequestInterceptor.Этот перехватчик дает мне доступ к запросу до его разрешения.Можно ли перехватить ответ на каждый перехваченный запрос без необходимости повторной отправки запроса вручную?

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 Версия: 5.11.2

...