如何使用 qtwebengine 禁用 cookie?
How to disable cookies using qtwebengine?
PyQt5.14 QWebEngineView 如何禁用cookies?我找不到对此的任何参考。
一个可能的选择是使用与配置文件关联的 QWebEngineCookieStore 来消除现有的 cookie 并建立一个过滤器来拒绝新的 cookie。
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
view = QtWebEngineWidgets.QWebEngineView()
cookie_store = view.page().profile().cookieStore()
def cookie_filter(request):
print(
f"firstPartyUrl: {request.firstPartyUrl.toString()}, origin: {request.origin.toString()}, thirdParty? {request.thirdParty}"
)
return False
cookie_store.setCookieFilter(cookie_filter)
cookie_store.deleteAllCookies()
view.load(QtCore.QUrl("https://www.qt.io"))
view.show()
sys.exit(app.exec_())
PyQt5.14 QWebEngineView 如何禁用cookies?我找不到对此的任何参考。
一个可能的选择是使用与配置文件关联的 QWebEngineCookieStore 来消除现有的 cookie 并建立一个过滤器来拒绝新的 cookie。
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
view = QtWebEngineWidgets.QWebEngineView()
cookie_store = view.page().profile().cookieStore()
def cookie_filter(request):
print(
f"firstPartyUrl: {request.firstPartyUrl.toString()}, origin: {request.origin.toString()}, thirdParty? {request.thirdParty}"
)
return False
cookie_store.setCookieFilter(cookie_filter)
cookie_store.deleteAllCookies()
view.load(QtCore.QUrl("https://www.qt.io"))
view.show()
sys.exit(app.exec_())