Я использовал пример pyqt5 (https://stackoverflow.com/search? q=pyqt5+forcepersistentcookies) и заставил его работать под PYQT6.
Моя цель — сделать так, чтобы браузер мог собирать URL-адрес страницы, которую я посещаю (и передавать его в калибратор), без необходимости вводить его снова и снова. информация, которая попадает в файлы cookie. Таким образом, второй доступ будет намного быстрее.
У меня есть минимальный фрагмент кода:
Код: Выделить всё
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QMainWindow
from PyQt6.QtWebEngineCore import QWebEnginePage, QWebEngineProfile
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtCore import QUrl
from pathlib import Path
import sys
site = "https://www.google.com/"
site = 'https://stackoverflow.com/search?q=pyqt5+forcepersistentcookies'
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
QMainWindow.__init__(self, *args, **kwargs)
self.webview = QWebEngineView()
profile = QWebEngineProfile("savecookies", self.webview)
print(f"unset... {QWebEngineProfile.persistentCookiesPolicy(profile)}, of the record? : {profile.isOffTheRecord()}")
profile.setPersistentCookiesPolicy(QWebEngineProfile.PersistentCookiesPolicy.ForcePersistentCookies)
browser_storage_folder = Path.home().as_posix() + '/.test_cookies'
profile.setPersistentStoragePath(browser_storage_folder)
self.webpage = QWebEnginePage(profile, self.webview)
self.webview.setPage(self.webpage)
self.webview.load(QUrl(site))
self.setCentralWidget(self.webview)
def closeEvent(self, qclose_event):
"""Overwrite QWidget method so that the folling message does NOT shows on the console :
"Release of profile requested but WebEnginePage still not deleted. Expect troubles !"
This is due to the fact that Qt wants QWebEnginePage to be removed first but python removes QWebEngineProfile first.
So we need to overwrite the closing order and close QWebEnginePage after """
# Sets the accept flag of the event object, indicates that the event receiver wants the event.
qclose_event.accept()
# Schedules this object for deletion, QObject
self.webpage.deleteLater()
Однако для stackoverflow меня всегда просят докажу, что я человек, и получаю на консоли неожиданную серию сообщений (дважды одно при открытии и другое при закрытии окна)
В сообщениях говорится:
Код: Выделить всё
js: Error with Feature-Policy header: Unrecognized feature: 'speaker'.
js: [GSI_LOGGER]: Your client application uses one of the Google One Tap prompt UI status methods that may stop functioning when FedCM becomes mandatory. Refer to the migration guide to update your code accordingly and opt-in to FedCM to test your changes. Learn more: https://developers.google.com/identity/gsi/web/guides/fedcm-migration?s=dc#display_moment and https://developers.google.com/identity/gsi/web/guides/fedcm-migration?s=dc#skipped_moment
js: [GSI_LOGGER]: Currently, you disable FedCM on Google One Tap. FedCM for One Tap will become mandatory starting Oct 2024, and you won't be able to disable it. Refer to the migration guide to update your code accordingly to ensure users will not be blocked from logging in. Learn more: https://developers.google.com/identity/gsi/web/guides/fedcm-migration
Подробнее здесь: https://stackoverflow.com/questions/786 ... am-a-human