I have a form.html
file and i run it using PyQt5 QWebEngineView
.
I want to retrieve form values after the Submit button is clicked. I've gone through many solutions but cannot find the perfect one.
Eg: I found this one but it works on URL Change
.
I'm just simply looking for a solution which works on clicking the Submit button.
Here's my code that i have used from the above link but i'm not getting any value returned from the form:
import os
import sys
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget
from PyQt5.QtCore import QUrl, QEventLoop
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInterceptor
class WebPage(QWebEngineView):
def __init__(self):
QWebEngineView.__init__(self)
filepath = os.path.abspath(os.path.join(os.path.dirname(__file__), 'form.html'))
self.load(QUrl.fromLocalFile(filepath))
self.loadFinished.connect(self._on_load_finished)
def _on_load_finished(self):
self.page().runJavaScript("document.getElementById('num1').value", self.store_value)
def store_value(self, param):
self.value = param
print("Param: " +str(param))
if __name__ == "__main__":
app = QApplication(sys.argv)
web = WebPage()
web.show()
sys.exit(app.exec_())
HTML:
<html>
<body>
<form>
Number 1:<input type="text" id="num1">
<br>
Number 2:<input type="text" id="num2">
<br>
<input type="submit" id="sub1">
</form>
</body>
</html>