Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QWebenginePage findText() method
radarjonathan last edited by
I have a problem with using findText() of QWebengineView. I want to build a programm, where I can search a HTML Page for specific words, mark them up and extract them by using the selectedText() method of QWebengineview/page. findText() works fine for searching the page and marking up all occurences of the words on the page. The words are found and the callback function shows "TRUE" for the callback "found". But when I call selectedText() the string is always empty, so nothing is selected on the page. Maybe i'm using the callback function wrong? I'm thankfull for every type of help!!
class App(QWidget): def __init__(self): '''Initializer of Main App''' super(App, self).__init__() self.resize(1920, 1080) self.view = QtWebEngineWidgets.QWebEngineView(self) self.view.resize(1920, 1080) self.url = QUrl('https://de.wikipedia.org/wiki/Michael_Phelps') self.view.load(self.url) self.button = QPushButton(self) self.button.clicked.connect(self.searchPage) self.button2 = QPushButton(self) self.button2.move(40,40) def searchPage(self): flags = QWebEnginePage.FindFlags(0) self.view.findText("Michael", flags ,self.callback) def callback(self, found): print(found) print(self.view.page().selectedText())
JonB last edited by
works fine for searching the page and marking up all occurences of the words on the page
I think that's all it's supposed to do. It does not select any text, only mark it, else anyway if there are multiple occurrences how would it select them all anyway?