[PyQt] Overriding QNetworkAccessmanager
Marcos Dione
m.dione at servicemagic.eu
Thu Jan 12 16:47:27 GMT 2017
I'm trying to override the QNetworkAccesManager class so I can capture the QNetworRequest's and QNetworkReply'es that go through it, but my methods are not being called:
#! /usr/bin/python3
from PyQt5.QtWebKitWidgets import QWebPage
from PyQt5.QtCore import QEventLoop, QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtNetwork import QNetworkAccessManager
app = QApplication([])
loop = QEventLoop()
class NetworkManager(QNetworkAccessManager):
def __init__(self, *args):
super().__init__(*args)
self.request = None
self.data = None
self.response = None
self.verb = None
def get(self, request):
print('here1')
self.verb = 'GET'
self.request = request
self.response = super().get(request)
return self.response
def post(self, request, data):
print('here2')
self.verb = 'POST'
self.request = request
self.data = data
self.response = super().post(request, data)
return self.response
class QtBrowser:
def __init__(self):
self.nam = NetworkManager()
self.page = QWebPage()
self.page.setNetworkAccessManager(self.nam)
self.frame = self.page.mainFrame()
self.frame.loadFinished.connect(loop.quit)
self.root = None
def open(self, url):
self.frame.load(QUrl(url))
loop.exec()
def update(self):
self.root = self.frame.documentElement()
if __name__ == '__main__':
browser = QtBrowser()
browser.open('https://duckduckgo.com/')
Is this possible somehow? Cheers,
-- Marcos.
---
DISCLAIMER: This e-mail is private and confidential and may contain proprietary or legally privileged information. It is for the intended recipient only. If you have received this email in error, please notify the author by replying to it and then destroy it. If you are not the intended recipient you must not use, disclose, distribute, copy, print or rely on this e-mail or any attachment. Thank you
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Marcos Dione.vcf
Type: text/vcard
Size: 193 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170112/c280bdc2/attachment.vcf>
More information about the PyQt
mailing list