L
L
lookatshow2019-09-24 16:43:20
Python
lookatshow, 2019-09-24 16:43:20

Switching from PyQt4 to PyQt5, the optimal solution?

Good day, friends, I used to work with page parsing through PyQt4, and now, to the best of circumstances, I had to switch to PyQt5, and no matter how long it has been serviced :)
I transferred many frameworks to QT5, but I can’t figure out QWebEngineView as QWebView, in particular
doc = view.page().mainFrame().documentElement()
code:

import sys

from PyQt5.QtNetwork import QNetworkProxyFactory, QNetworkRequest
from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView, QWebEnginePage
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *


if __name__ == '__main__':
    app = QApplication(sys.argv)

    # Чтобы не было проблем запуска компов с прокси:
    QNetworkProxyFactory.setUseSystemConfiguration(True)

    QWebSettings.globalSettings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)

    view = QWebView()
    view.page()
    view.show()
    view.setUrl(QUrl('https://www.myscore.ru/match/lhcHgzkK/#match-summary'))
    # Ждем пока прогрузится страница

    loop = QEventLoop()
    view.loadFinished.connect(loop.quit)
    loop.exec_()

    doc = view.page().mainFrame().documentElement()
    print(doc.findFirst("#statistics-0-statistic a").toPlainText())
    print(doc.findFirst("#statistics-1-statistic a").toPlainText())
    print(doc.findFirst("#statistics-2-statistic a").toPlainText())

    table = doc.findFirst("#tab-statistics-0-statistic .parts")
    for tr in table.findAll('tr'):
        l, text, r = tr.toPlainText().split('\t')
        print(l, text, r)

    # sys.exit(app.exec_())

Mistake:
line 32, in <module>
    doc = view.page().mainFrame().documentElement()
AttributeError: 'QWebEnginePage' object has no attribute 'mainFrame'

I can not find an alternative in the manual of the 5th version.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question