So, the question is on using QWebEngineView
or QWebEnginePage
, or something like that. I have a link which looks like <a href="/salt">Salt</a>
. I have already managed to intercept clicking on this link and force QWebEngineView
to do nothing with it because all that I need is to print the text of this url ("Salt") in the python console instead of opening it. The problem is that I haven't any idea how to implement it. There was linkHovered()
signal in PyQt4 which returns the title, text and url of the link when the mouse hovers over it. In PyQt5 it returns only the url. Any ideas?
Some code:
class MyWebEnginePage(QWebEnginePage):
link_clicked = pyqtSignal(str)
def acceptNavigationRequest(self, url, nav_type, is_frame):
if nav_type == 0:
self.link_clicked.emit(str(url))
return False
else:
return True
self.page.link_clicked.connect(self.LEchange)
def LEchange(self,url):
print(url)
It prints:
PyQt5.QtCore.QUrl('file:///C:/salt')
but if the link looks like <a href="/salt">Salt</a>
I need to get "Salt".