猿问

PyQt5 QWebEngine 禁用 Access-Control-Allow-Origin

我需要让我的程序在它访问的任何网站上删除 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?


函数式编程
浏览 311回答 1
1回答
随时随地看视频慕课网APP

相关分类

Python
我要回答