Получить содержимое встроенной HTML-страницы в pyqt5.10 с помощью QtWebEngineWidgets.QWebEngineView.page().tohtml

Я действительно новичок в pyqt. Я работаю над почтовой системой с pyqt5.10 и QTdesigner в pycharm. Это моя домашняя работа. я нахожу связанный код в pyqt4 и пытаюсь преобразовать его в pyqt5.10 и модифицированный код:

это в ui_writemail.py

self.richEmailEdit = QtWebEngineWidgets.QWebEngineView(WriteEmailDialog)
self.richEmailEdit.setGeometry(QtCore.QRect(0, 140, 721, 411))
self.richEmailEdit.setProperty("url", QtCore.QUrl("D:\mail_1049677709\kindeditor-4.1.7\examples/default.html"))
self.richEmailEdit.setObjectName("richEmailEdit")

это в writemail.py

self.page = self.richEmailEdit.page() 

def GetEmailHtml(self):
    self.page.runJavaScript('''document.getElementById('emailHtml').innerHTML = editor.html();''')
    print('g1')
    html = self.richEmailEdit.page().toHtml()
    print('g2')
    emailName = self.dir + self.subjectEdit.text()
    emailHtml = \
    html.split('<textarea name="emailHtml" id="emailHtml" cols="30" rows="10">')[1].split("</textarea>")[0]
    emailHtml = emailHtml.replace('&lt;', '<').replace('&gt;', '>')
    print('g3')
    return emailHtml

richEmailEdit предназначен для получения содержимого встроенной html-страницы в Qwebview в designer.and результат отладки следующий:

g1
toHtml(self, Callable[..., None]): not enough arguments

я знаю, что tohtml нужны некоторые аргументы, но я не знаю, как изменить, потому что не найдено никаких связанных документов. я пытаюсь сделать это:

def GetEmailHtml(self):
    self.page.runJavaScript('''document.getElementById('emailHtml').innerHTML = editor.html();''')
    print('g1')
    html = self.richEmailEdit.page().toHtml(self.callable)
    print('g2')
    emailName = self.dir + self.subjectEdit.text()
    emailHtml = \
    html.split('<textarea name="emailHtml" id="emailHtml" cols="30" rows="10">')[1].split("</textarea>")[0]
    emailHtml = emailHtml.replace('&lt;', '<').replace('&gt;', '>')
    print('g3')
    return emailHtml

def callable(self, html):
    print(html)

и ошибки:

g1
g2
'NoneType' object has no attribute 'split'
<!DOCTYPE html><html><head>
    <meta charset="utf-8">
    <title>Default Examples</title>
    <style>
        form {
            margin: 0;
        }
        textarea {
            display: block;
        }
    </style>
    <link rel="stylesheet" href="../themes/default/default.css">
    <script charset="utf-8" src="../kindeditor-min.js"></script>
    <script charset="utf-8" src="../lang/zh_CN.js"></script>
    <script>

        var editor;
        KindEditor.ready(function(K) {
            editor = K.create('textarea[name="content"]', {
                allowFileManager : true,
                resizeType : 1,
                allowPreviewEmoticons : false,
                allowImageUpload : false,
                items : [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                    'insertunorderedlist', '|', 'emoticons', 'image', 'link', '|','fullscreen'],
                resizeMode : 0,
                height:'300px',
                minHeight:300,
                autoHeightMode : true,
            });
            K('input[name=getHtml]').click(function(e) {
                document.getElementById('emailHtml').innerHTML = editor.html();
            });
            K('input[name=clear]').click(function(e) {
                editor.html('');
            });
        });
    </script>
</head>
<body>
    <form>
        <div class="ke-container ke-container-default" style="width: 692px;"><div style="display:block;" class="ke-toolbar" unselectable="on"><span class="ke-outline" data-name="fontname" title="字体" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-fontname" unselectable="on"></span></span><span class="ke-outline" data-name="fontsize" title="文字大小" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-fontsize" unselectable="on"></span></span><span class="ke-inline-block ke-separator"></span><span class="ke-outline" data-name="forecolor" title="文字颜色" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-forecolor" unselectable="on"></span></span><span class="ke-outline" data-name="hilitecolor" title="文字背景" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-hilitecolor" unselectable="on"></span></span><span class="ke-outline" data-name="bold" title="粗体(Ctrl+B)" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-bold" unselectable="on"></span></span><span class="ke-outline" data-name="italic" title="斜体(Ctrl+I)" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-italic" unselectable="on"></span></span><span class="ke-outline" data-name="underline" title="下划线(Ctrl+U)" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-underline" unselectable="on"></span></span><span class="ke-outline" data-name="removeformat" title="删除格式" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-removeformat" unselectable="on"></span></span><span class="ke-inline-block ke-separator"></span><span class="ke-outline ke-selected" data-name="justifyleft" title="左对齐" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-justifyleft" unselectable="on"></span></span><span class="ke-outline" data-name="justifycenter" title="居中" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-justifycenter" unselectable="on"></span></span><span class="ke-outline" data-name="justifyright" title="右对齐" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-justifyright" unselectable="on"></span></span><span class="ke-outline" data-name="insertorderedlist" title="编号" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-insertorderedlist" unselectable="on"></span></span><span class="ke-outline" data-name="insertunorderedlist" title="项目符号" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-insertunorderedlist" unselectable="on"></span></span><span class="ke-inline-block ke-separator"></span><span class="ke-outline" data-name="emoticons" title="插入表情" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-emoticons" unselectable="on"></span></span><span class="ke-outline" data-name="image" title="图片" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-image" unselectable="on"></span></span><span class="ke-outline" data-name="link" title="超级链接" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-link" unselectable="on"></span></span><span class="ke-inline-block ke-separator"></span><span class="ke-outline" data-name="fullscreen" title="全屏显示" unselectable="on"><span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-fullscreen" unselectable="on"></span></span></div><div style="display: block; height: 300px;" class="ke-edit"><iframe class="ke-edit-iframe" hidefocus="true" frameborder="0" style="width: 100%; height: 300px;"></iframe><textarea class="ke-edit-textarea" hidefocus="true" style="width: 100%; height: 300px; display: none;"></textarea></div><div class="ke-statusbar"><span class="ke-inline-block ke-statusbar-center-icon"></span><span class="ke-inline-block ke-statusbar-right-icon" style="visibility: hidden;"></span></div></div><textarea id="content" name="content" style="width: 692px; visibility: hidden; display: none;">                请输入邮件信息
        </textarea>
        <p>
            <input type="button" name="clear" value="清空内容">
        </p>
    </form>
    <div style="display: none;">
    <textarea name="emailHtml" id="emailHtml" cols="30" rows="10">请输入邮件信息e5 mws46g 4w</textarea>
    </div>

0 ответов

Другие вопросы по тегам