diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index c49089d..97bf480 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -64,6 +64,7 @@ encoding//QWebEngineView/SiteDiffUser.py=utf-8 encoding//QWebView/DreamTree.py=utf-8 encoding//QWebView/GetCookie.py=utf-8 encoding//QWebView/JsSignals.py=utf-8 +encoding//QWebView/PlayFlash.py=utf-8 encoding//QWebView/ScreenShotPage.py=utf-8 encoding//QWidget/Lib/CustomPaintWidget.py=utf-8 encoding//QWidget/Lib/CustomWidget.py=utf-8 diff --git a/QWebView/Data/NPSWF32.dll b/QWebView/Data/NPSWF32.dll new file mode 100644 index 0000000..9f24171 Binary files /dev/null and b/QWebView/Data/NPSWF32.dll differ diff --git a/QWebView/PlayFlash.py b/QWebView/PlayFlash.py new file mode 100644 index 0000000..dc992f5 --- /dev/null +++ b/QWebView/PlayFlash.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Created on 2019年9月18日 +@author: Irony +@site: https://pyqt5.com https://github.com/892768447 +@email: 892768447@qq.com +@file: QWebView.PlayFlash +@description: 播放Flash +""" +import os +import sys + +from PyQt5.QtCore import QUrl +from PyQt5.QtNetwork import QSslConfiguration, QSslCertificate, QSsl +from PyQt5.QtWebKit import QWebSettings +from PyQt5.QtWebKitWidgets import QWebView +from PyQt5.QtWidgets import QApplication + + +__Author__ = 'Irony' +__Copyright__ = 'Copyright (c) 2019 Irony' +__Version__ = 1.0 + + +class Window(QWebView): + + def __init__(self, *args, **kwargs): + super(Window, self).__init__(*args, **kwargs) + self.resize(800, 600) + # 浏览器设置 + setting = QWebSettings.globalSettings() + setting.setAttribute(QWebSettings.PluginsEnabled, True) + # 解决xp下ssl问题 + self.page().networkAccessManager().sslErrors.connect(self.handleSslErrors) + sslconf = QSslConfiguration.defaultConfiguration() + clist = sslconf.caCertificates() + cnew = QSslCertificate.fromData(b"CaCertificates") + clist.extend(cnew) + sslconf.setCaCertificates(clist) + sslconf.setProtocol(QSsl.AnyProtocol) + QSslConfiguration.setDefaultConfiguration(sslconf) + + def handleSslErrors(self, reply, errors): + # 解决ssl错误 + reply.ignoreSslErrors() + + +if __name__ == '__main__': + # 非常重要,设置为NPSWF32.dll文件所在目录 + os.environ['QTWEBKIT_PLUGIN_PATH'] = os.path.abspath('Data') + app = QApplication(sys.argv) + w = Window() + w.show() + w.load(QUrl('https://www.17sucai.com/preview/8825/2013-07-07/%E4%B8%80%E6%AC%BE%E4%BA%BA%E5%BD%A2%E5%8A%A8%E4%BD%9C%E6%98%BE%E7%A4%BA%E7%9A%84flash%E6%97%B6%E9%97%B4/index.html')) + sys.exit(app.exec_()) diff --git a/QWebView/README.md b/QWebView/README.md index e74be8a..345a6ba 100644 --- a/QWebView/README.md +++ b/QWebView/README.md @@ -37,4 +37,12 @@ 最后通过`QWebFrame.render`把图片截出来 2. 方式2:通过js库`html2canvas`对指定元素截图,得到`base64`编码的数据并调用接口函数传递到py代码中 -![ScreenShotPage](ScreenShot/ScreenShotPage.gif) \ No newline at end of file +![ScreenShotPage](ScreenShot/ScreenShotPage.gif) + +## 5、播放Flash +[运行 PlayFlash.py](PlayFlash.py) + +1. 重点在于设置 `os.environ['QTWEBKIT_PLUGIN_PATH'] = os.path.abspath('Data')` ,非常重要,设置为NPSWF32.dll文件所在目录 +2. 其次是xp下ssl问题,具体参考代码 + +![PlayFlash](ScreenShot/PlayFlash.gif) \ No newline at end of file diff --git a/QWebView/ScreenShot/PlayFlash.gif b/QWebView/ScreenShot/PlayFlash.gif new file mode 100644 index 0000000..d22f1aa Binary files /dev/null and b/QWebView/ScreenShot/PlayFlash.gif differ diff --git a/README.md b/README.md index b0d79ed..6ea6cf9 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站 - [获取Cookie](QWebView/GetCookie.py) - [和Js交互操作](QWebView/JsSignals.py) - [网页整体截图](QWebView/ScreenShotPage.py) + - [播放Flash](QWebView/PlayFlash.py) - [QWebEngineView](QWebEngineView) - [获取Cookie](QWebEngineView/GetCookie.py) - [和Js交互操作](QWebEngineView/JsSignals.py)