Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

[[qanda:topic_unsolved]] QWebenginePage findText() method

$
0
0

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())

Viewing all articles
Browse latest Browse all 13965

Trending Articles