我知道这是一个老问题,但我想我会尝试给碰巧碰到它的人找一个答案.你可以创建一个QNetworkAccessManager的子类并将它与
https://github.com/atereshkin/abpy结合起来.有点像这样:
from PyQt4.QtNetwork import QNetworkAccessManager
from abpy import Filter
adblockFilter = Filter(file("easylist.txt"))
class MyNetworkAccessManager(QNetworkAccessManager):
def createRequest(self, op, request, device=None):
url = request.url().toString()
doFilter = adblockFilter.match(url)
if doFilter:
return QNetworkAccessManager.createRequest(self, self.GetOperation, QNetworkRequest(QUrl()))
else:
QNetworkAccessManager.createRequest(self, op, request, device)
myNetworkAccessManager = MyNetworkAccessManager()
之后,在所有QWebView实例上设置以下内容,或者创建QWebView的子类:
QWebView.page().setNetworkAccessManager(myNetworkAccessManager)
希望这可以帮助!