前提・実現したいこと
pyqt5を使い、webサイトのコンテンツを表示したいです。
例:https://www.yahoo.co.jp/のトッピックスのみを表示する
該当のソースコード
python
1import sys 2from PyQt5.QtWidgets import * 3from PyQt5.QtWebKitWidgets import QWebView 4import test_ui 5 6class Test(QDialog): 7 def __init__(self, parent=None): 8 super(Test, self).__init__(parent) 9 self.ui = test_ui.Ui_Form() 10 self.ui.setupUi(self) 11 html = ''' 12 <html> 13 <head> 14 <title>A Sample Page</title> 15 </head> 16 <body> 17 <script> 18 $(function(){ 19 $.ajax({ 20 url: 'https://www.yahoo.co.jp/', 21 cache: false, 22 datatype: 'html', 23 success: function(html) { 24 var h = $(html).find('topicsbox'); 25 $('#wrap').append(h); 26 } 27 }); 28 }); 29 </script> 30 <div id="wrap"> 31 <!-- ここにajaxで呼び出したコンテンツ(=要素)が出力される --> 32 </div> 33 </body> 34 </html> 35 ''' 36 37 self.ui.webView.setHtml(html) 38 self.show() 39 40 41if __name__ == "__main__": 42 app = QApplication(sys.argv) 43 myapp = Test() 44 myapp.show() 45 app.exec_()
試したこと
下記URLなどを参考にhtmlで記述して表示しようとしてみましたがうまくいきませんでした。
https://designsupply-web.com/knowledgeside/2086/
あなたの回答
tips
プレビュー