gpt4 book ai didi

python - PyQt5 QWebEngine 禁用 Access-Control-Allow-Origin

转载 作者:行者123 更新时间:2023-12-01 08:53:20 25 4
gpt4 key购买 nike

我需要让我的程序在其访问的任何网站上删除 Access-Control-Allow-Origin,我该如何执行此操作?这是我现在的代码:

from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.webView = QtWebEngineWidgets.QWebEngineView(self.centralwidget)
self.webView.setUrl(QtCore.QUrl("thewebsite"))
self.webView.loadFinished.connect(self.reform)
self.webView.setObjectName("webView")
self.gridLayout.addWidget(self.webView, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def reform(self, ok):
payload = open('payload.js', 'r').read()
if ok:
self.webView.page().runJavaScript('alert("Ready");')
self.webView.page().runJavaScript(payload)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))

from PyQt5 import QtWebEngineWidgets

if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.setFixedSize(500, 500)
MainWindow.show()
sys.exit(app.exec_())

如何才能禁用 Access-Control-Allow-Origin?

最佳答案

您可以尝试启用LocalContentCanAccessRemoteUrls WebAttribute :

if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
settings = QtWebEngineWidgets.QWebEngineSettings.defaultSettings()
settings.setAttribute(QtWebEngineWidgets.QWebEngineSettings.LocalContentCanAccessRemoteUrls, True)
...

关于python - PyQt5 QWebEngine 禁用 Access-Control-Allow-Origin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52959789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com